Loopback有两个区域,为静态文件设置路径:
server.js
var path = require('path');
app.use(loopback.static(path.resolve(__dirname, '../client')));
middleware.json
"files": {
"loopback#static": {
"params": "$!../client"
}
},
在我的开发环境中,我还想引用另一个目录,例如/node_modules
我该怎么做?
答案 0 :(得分:38)
在loopback.static
中多次注册server.js
:
...
app.use(loopback.static(path.resolve(__dirname, '../client')));
app.use(loopback.static(path.resolve(__dirname, '../other-dir')));
...
第一个优先级最高。有关详细信息,请参阅http://expressjs.com/api.html。
您也可以在middleware.json
内查看相位(请参阅docs):
"files": {
"loopback#static": [{
"name": "client",
"paths": ["/client"],
"params": "$!../client"
},
{
"name": "someother",
"paths": ["/someother"],
"params": "$!../someother"
}]
}