express icon indicating copy to clipboard operation
express copied to clipboard

Redirect: False Not Affecting Behavior

Open ewwwgiddings opened this issue 1 year ago • 4 comments

I started using express as part of Angular Universal and started facing this issue: https://github.com/angular/universal/issues/2827

  1. Request with no trailing slash (/welcome)
  2. A 301 redirect returned to request with location including the trailing slash (/welcome/)
  3. 200 OK returned
  4. Trailing slash stripped in the URL bar in browser

I see other people have brought it up and the answer is usually try redirect: false so that server-static doesn't add the trailing slash.

Problem is I tried using that using Angular Universal 10.1.1 and Express 4.15.2 and it had no effect.

Does Express / Node have any sort of caching that would cause this change to not show and if so anyone know how to prevent that? Is it working for everyone else still?

ewwwgiddings avatar Sep 21 '22 16:09 ewwwgiddings

Hi @ewwwgiddings sorry for your issue. It is certainly possible that something else outside of serve-static is performing the redirect, which is why redirect: false there is having no effect; that answer would only apply if that is were your redirect is coming from. Express.js itself has no caching internally. We can help, but there are too many unknowns and we would need your complete application and reproduction steps in order to debug through it to determine where the redirect originates.

dougwilson avatar Sep 21 '22 16:09 dougwilson

I checked everything else all through every file in the node_modules and I'm fairly certain it's serve-static. I didn't see any other code giving a redirect. I can get a basic app set up with the issue and attach it here when I do. Thank you!

ewwwgiddings avatar Sep 21 '22 16:09 ewwwgiddings

Sounds good, I'm glad to help. If you're able to alter your node_modules contents for your app, another thing you can always try to validate that it is serve-static is you can comment out the actual code lines that send the redirect (or even just change them to send a 500 instead) that would indicate that indeed that is the source.

https://github.com/expressjs/serve-static/blob/9b5a12a76f4d70530d2d2a8c7742e9158ed3c0a4/index.js#L202

dougwilson avatar Sep 21 '22 16:09 dougwilson

That's a great test. Thanks for that idea. The reason I started thinking cache and asking about that with Express/Node was that I started changing stuff and there didn't seem to be anything happening as a result. One thing was altering that file you linked for redirect to always be false. I'll give your idea a shot in a little bit here. Thanks again.

ewwwgiddings avatar Sep 21 '22 16:09 ewwwgiddings

We can close this. I'm working on another way around this and I'm no longer thinking it's certain to be related to this. Thank you a ton for your help!

ewwwgiddings avatar Sep 23 '22 21:09 ewwwgiddings