0
votes

I'm sorry if this question is answer somewhere else.

I want to send static html file when url contains parameters. For example, http://localhost:3000/detail.html/1, but the path kind messed up. Here is my problem, I used app.use(express.static(path.join(__dirname, 'public'))); for all static files request with no parameters,
and for this http://localhost:3000/detail.html/:id request, I used

app.get('/detail.html/:id', function(req, res){
var options = {
root: __dirname + '/public/'


};

 res.sendFile(  'detail.html',options);
});

I can get detail.html page in browser, but all my css link and images src in detail.html are relative, and request became like this: /detail.html/css/custom.css rather than just /css/custom.css.

And my file structure is all html files are in public folder, and css files are in public/css folder.

Where am I wrong? and how should solve the problem? Thanks!

1

1 Answers

0
votes

You can rename your detail.html as index.html and add a route in your expressjs code as,

app.get('/', function (req, res) {
  res.sendfile('__dirname + '/public/' + index.html);
})

Then, you will not be having the html static file in your url and things will work