0

I want to get parameters from url and display content based on the parameters.

I am using express 4 here is my code

app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/public'));

app.get('/showcontent/:book/:page',
  function(req, res) {
    console.log("app.get parameters");

    res.render('bookPage', { book: req.params.book,page: req.params.page });
  }
);

in my public folder there are css and js files. when i use url with parameters like

mydomain.com/showcontent/book/page123

it tries to get css and js files from

mydomain.com/showcontent/book/page123/css/style.css
mydomain.com/showcontent/book/page123/js/script.js

while it should get the files from public folder from url

mydomain.com/css/style.css
mydomain.com/js/script.js

everything works fine if I use url format like this

/showcontent?book=1234&page=12345

but i dont want to use this format, I think some thing is missing in my code please someone help me solve to get parameters from url using forward slash format and still get css and js files from public directory

Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
sarfarazsajjad
  • 1,208
  • 2
  • 17
  • 30
  • 1
    See [this answer](http://stackoverflow.com/a/23447587/142162) (summary: use absolute paths for your CSS and JavaScript files). –  Nov 05 '14 at 16:18
  • possible duplicate of [Link to static files from Jade template rendered from a sub route](http://stackoverflow.com/questions/23447449/link-to-static-files-from-jade-template-rendered-from-a-sub-route) – Paul Sweatte Feb 07 '15 at 20:39

0 Answers0