krakig krakig -4 years ago 364
Node.js Question

Using express middleware in Sails.js to serve static files

I have trouble using the express middleware on sails 0.11.0. I tried the following in http.js file.

module.exports.http = {

customMiddleware: function (app) {
app.use('/test', express.static('****/****/*****/testProject/api/controllers' + '/public/'));


But it doesn't work, I am missing something.

Answer Source

Your syntax is a little off and you need to return the execution from the provided call back. It should look just like a controller.action.

I'm including the example from docs, this should help you

 * HTTP Server Settings
 * (sails.config.http)
 * Configuration for the underlying HTTP server in Sails.
 * Only applies to HTTP requests (not WebSockets)
 * For more information on configuration, check out:

module.exports.http = {

    order: [

    myRequestLogger: function (req, res, next) {
        console.log("Requested :: ", req.method, req.url);
        return next();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download