简体   繁体   中英

How to know if incoming requests are asking for HTML in express.js (rather than CSS, JS, etc)

How can I check to see if an incoming request in express.js is asking for HTML? As opposed to other static assets like CSS, JS, images, etc.

What I'd like to do is force a redirect on paths that contain uppercase letters (force paths to lowercase) so that I don't end up with duplicate links out there.

I don't want this to affect requests for static assets like images, CSS sheets, PDFs, etc.

In general - you can't.

The Accept request header can give you a list of types that the client will accept, but that will often include catch-all wildcards.

You could handle this at the handler level (and test the URL for uppercase characters inside the routes that you respond with HTML on).

That said - I don't see why you would want to avoid duplicate URLs to HTML documents but not to other kinds of files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM