简体   繁体   中英

Serving static files in node.js - 500 internal server error

I'm having a weird issue where our staging server is throwing a 500 error when trying to retrieve css or js assets. We are using broccoli to compile the assets to a distribution directory, so I have ~/dist/assets/app.css (as well as app.js and an img directory). Images seem to be served fine! Only the app.js and app.css files are throwing the 500 error. I've ensured the files definitely exist in their proper places. We're using express.js and the serve-static module. Code is simply:

serveStatic = require('serve-static');
app.use(serveStatic('dist/assets'));

Then hitting ' http://url.com/assets/app.css ' throws the 500. Hitting ' http://url.com/app.css ' WORKS. This seems like it would be okay (since I'm serving dist/assets so the request should be relative to /assets), but this was all working with the /assets prefix on the request a few days ago. There is no error output produced in the logs anywhere. Stumped on this one. I just want to make sure I'm not doing anything too dumb.

Have you tried this:

serveStatic = require('serve-static');
app.use(serveStatic('dist'));

serveStatic(root, options)

Create a new middleware function to serve files from within a given root directory.

Based on that statement, you should expect that using "serveStatic('dist/assets')" will serve the app.css from http://url.com/app.css

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