在sail.js中定制中间件

在我的Sails应用程序中,我想访问不在“资产”中的静态文件夹。

在expression中,我可以通过设置例如:

app.use('/ static_path',express.static(__ dirname +'/ views / static_path'));

所以在Sails中,我尝试在“config / http.js”中添加一个中间件。

这是我的问题。 当我添加自定义中间件时:

customMiddleware:function(app){var express = require('../ node_modules / sails / node_modules / express');

app.use('/static_path', express.static(__dirname + '/../views/static_path')); } 
  1. 根据文档,我应该能够通过将$ custom传入“order”(列出所有中间件)来访问“CustomMiddleware”。 但是中间件不会被这种方式调用
  2. 其实在“顺序”列表中,如果我添加单词“customMiddleware”,它的工作。 但第二点是,应用程序崩溃和日志

app.use不是一个函数

有人可以帮我吗? 对不起对我的英文顺便说一下

在使用app.use之前,您需要明确expression。

尝试这样的事情:

configuration/ http.js

 var express = require('express'); // if you have npm version > 2 // var express = require('sails/node_modules/express'); // for older npm versions module.exports.http = { customMiddleware: function (app) { app.use('/static_path', express.static(__dirname + '/../views/static_path')); }, ... rest of the http.js