Harazi / range

Middleware for serving static files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trailing slash for directories

Harazi opened this issue · comments

Serving index files without trailing slash in the request path will led to relative path issues.

For example, this is your file structure:

.
├── example
│     └── index.html
│     └── style.css
└── app.js

And your index.html file contain style link with relative path <link rel="stylesheet" href="style.css">, and you write your routes without strict routing.

app.get("/example/", range())

If the user request was without trainling slash http://localhost/example, then the next request (the stylesheet) will be like this http://localhost/style.css, which doesn't have a valid route.

One solution is to enable express strict routing, But then the user will be left with 404 Not Found.

A better more managed solution is to redirect the user to a trailing slash url from inside range.