在 Loopback 中为静态文件添加多个目录

Add multiple dir for static files in Loopback

Loopback有两个区域为静态文件设置路径:

server.js

   var path = require('path');
   app.use(loopback.static(path.resolve(__dirname, '../client')));

middleware.json

"files": {
    "loopback#static": {
      "params": "$!../client"
      }
  },

在我的开发环境中,我还想引用另一个目录,例如 /node_modules

我该怎么做?

server.js中多次注册loopback.static

...
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"
    }]
}