-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using '*' with express.static redirects all the urls #3660
Comments
This is because the star will slurp up the entire URL and now express.static thinks every request is to the base URL. What are you expecting the behavior to be when you do that? |
Sorry to post what seems to be a stackoverflow question. At first I thought that was an unexpected behavior and decided to open this issue but now I understand why I got these redirects. Before closing this thread I'd be glad to hear if you know any way to redirect all URLs to the same base URL. What I am trying to achieve is to redirect all requested URLs to the same index file, except for resources files (.js, .css, .png, .jpg, etc...). Thanks |
@dougwilson Ok I am closing now as I make a fool of myself. I just understand that |
Typically I do something like this to solve the problem you are describing: app.use('/static', static('.'))
app.use((req, res) => {
res.render('index');
}) Then I point the asset urls to |
@wesleytodd thanks for your answer, this is exactly what I found out today. I knew I was doing something wrong, because I was dynamically creating routes. I thought |
Almost a whole year has passed since this issue arose but now something similar is happening to me. So, after reading here and there I've come to the conclusion that if you need a path that covers every URL that starts with it you just write your path without an asterisk as in the following example: As first, I was using |
I am facing quite an unexpected behavior. I am using express for my back-end REST api and to serve the statics which is a Polymer front-end application. If I use
and start my node app, and request
http://localhost:3000/
, the application works normally. Again it is a Polymer application that means if I click on local links the page is not refreshing because it's using thehistory
api, so for instance if I click<a href="/about">about</a>
the application will just load the appropriate view and will request appropriate data using an Ajax mechanism. That means the application seems to work normally but If I refresh the page say while the URL ishttp://localhost:3000/about
express won't have a clue what/about
route is and will just outputCannot GET /about
on the page.My Polymer apps need to be able to handle every URLs because there is also a 404 view, so it's ok to direct all routes to the same statics. My first thought was to write :
But now I encounter this issue where express tries to redirect (301) all my URLs,
it redirects all URLs even the static files like scripts and try to add a trailing slashes, which results in a complete fails to load my application..
The text was updated successfully, but these errors were encountered: