question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Force trailing slash

See original GitHub issue

Expected 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:closed
  • Created 5 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MartinMuzatkocommented, Aug 12, 2018

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?

0reactions
michalhainccommented, May 22, 2019

I could do it as well I believe…

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found