I have a local website with "Nodejs" (using "Express" framework). I'm using express route for showing each file in my directory and if the file that requested isn't in my directory I want to render
not-found.html
.
But I realized a weird things happen.
Here it's the issue:
when user enter something like this: "http://localhost:3000/swgw" the last middleware execute and "not-found.html" render property. (with css style)
when user enter URL like following pattern: "http://localhost:3000/products/*" the problem is this time not-found.html
render without css style. (Note: * isn't 1-6)
- public
- products
- product-1.html
- product-2.html
- product-3.html
- product-4.html
- product-5.html
- product-6.html
- style
- not-found.css
- not-found.html
- products
server.js
server.js``` ... app.use(express.static(path.join(__dirname, 'public'))); app.get("/products/:id", (req, res, next) => { // since I have six product with id from 1 to 6. if (req.params.id <= 6 && req.params.id >= 1) { res.setHeader('content-type', 'text/html'); return res.sendFile(path.resolve(`public/products/product-${req.params.id}.html`)); } else { next(); } }); app.get('*', function(req, res){ res.status(404); res.sendFile(path.resolve('public/not-found.html')); }); ```
not-found.html... <link rel="stylesheet" href="./style/not-found.css" > ...