javascript - Express adds first part of URL to injections if you use 2 level URLs? -


i using node.js + express.

when have 1-level url like:

/estonia 

all of scripts , styles loaded correctly if have 2-level url like:

/estonia/tallinn 

scripts , styles injections failing because adds /estonia path:

before: http://localhost:5050/js/config.js
after: http://localhost:5050/estonia/js/config.js

here routes.js file:

app.get('*', function(req, res) {     var url = req.url.slice(1);     var urlparamsarray = url.split("/");     if ( countries[urlparamsarray[0]] && (urlparamsarray.length===1 || cities[urlparamsarray[1]]) ) {         res.sendfile(config.root_path +'/'+ config.public_path+'/index.html');     } else {         res.status(404).sendfile(config.root_path + '/'+ config.public_path+'/404.html');     } }); 

here express.js file:

app.set('view engine', 'ejs'); app.use(function (req, res, next) {     res.header('access-control-allow-origin', '*');     res.header('access-control-allow-methods', 'get,put,post,delete');     res.header('access-control-allow-headers', 'content-type, authorization');     next(); });  app.use(bodyparser()); app.use(bodyparser.json()); app.use(bodyparser.urlencoded({     extended: true })); app.use(session({secret:config.express_session_secret})); app.use(favicon(config.root_path+'/public/favicon.ico')); app.use(express.static(config.root_path+"/"+config.public_path)); 

how can fix that?

add <base href="/"> <head> section of templates.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -