简体   繁体   中英

Second express.static not working online

I have my code locally working well, but when I pull my code on my digitalocean web server, my code doesn't work like locally.

app.configure(function(){
  app.use(express.bodyParser());
   app.use(express.static(__dirname + '/dynamicApp'));
   app.use(express.static(__dirname + '/staticApp'));
});

When I try to access content in /staticApp it works locally, but it doesn't on my digital ocean server. Content in the /dynamicApp work properly.

Both environment have the same node.js version (0.10.17), I have loaded with Vim my server files, and they are the same. I have done ls in all folders, and the structure is the same. I tried in incognito mode in Chrome to see if it were caching issues, and the issue is still there.

Anyone has a clue why this could happen ?

try setting the paths that serve the static content like:

app.configure(function(){
  app.use(express.bodyParser());
   app.use('/dynamicApp', express.static(__dirname + '/dynamicApp'));
   app.use('/staticApp', express.static(__dirname + '/staticApp'));
});

express 4.x , like this:

app.use('/public', express.static(__dirname+'/public'));

app.use('/data', express.static(__dirname+'/data'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM