Force trailing slash
See original GitHub issueExpected behavior
I want my front-ends to strictly end with a slash - otherwise their contents fail to load. (browser reads /app
- while contents reside in e.g. /app/main.js
and the browser tries to load from /main.js
instead. Which is wrong.
I tried to use the express-slash
plugin, but to no success. I suppose this only works when there are already routers are set up, but in this case, proxy works differently maybe.
Actual behavior
always add a trailing slash when using express-slash.
Setup
- http-proxy-middleware: 0.18.0
- server: express: 4.16.3
- express-slash: 2.0.1
proxy middleware configuration
const proxy = require('http-proxy-middleware')
const express = require('express')
const slash = require('express-slash')
let app = express()
app.use(
'/app/',
proxy(
{
pathRewrite: { '^/app' : '' },
target: 'http://localhost:1881',
}
)
)
app.enable('strict routing')
app.use(slash())
app.listen(80)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Force Trailing Slash with .htaccess - WP-Mix
This quick code snippet enables you to enforce that all directory URLs append a trailing slash. It is a very simple code snippet, ......
Read more >htaccess Rewrite to Force Trailing Slash at the end
You can do this to force trailing slash for all URLs that do not point directly to a file using !-f in the...
Read more >How to force https, www and a trailing slash with one redirect
The right way is to make the .htaccess check for the / then check for www. and https:// . If any of our...
Read more >Force trailing slash to avoid duplicate content using htaccess
By forcing the trailing slash on your URL's you prevent duplicate URLs and also keeps your analytics tidier as there will only be...
Read more >gatsby-plugin-force-trailing-slashes
A web-server that treats trailing-slash paths as directories with an index.html inside and non-trailing-slash paths as named documents (and ideally redirects ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That is again not true. If my app loads from localhost/app, and the html loads
<script src="main.js">
from where do you think will the browser attempt to load the file? From localhost/main.js or localhost/app/main.js?Without a slash at the end, the browser wants to load from the location where the last slash occured. I think there is no other way to rewriting this other than putting a slash at the end.
Now i want to write my apps independent without knowledge of the paths. Is there a way to do it?
I could do it as well I believe…