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

时间:2015-02-25 21:24:25

标签: loopbackjs

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

server.js

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

middleware.json

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

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

我该怎么做?

1 个答案:

答案 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"
    }]
}