19

Loopback has two areas where paths are set for static files:

server.js

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

middleware.json

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

In my dev environment I'd also like to reference another dir for example /node_modules

How do I do this?

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
Lee
  • 1,389
  • 3
  • 18
  • 28

1 Answers1

42

Register loopback.static multiple times in server.js:

...
app.use(loopback.static(path.resolve(__dirname, '../client')));
app.use(loopback.static(path.resolve(__dirname, '../other-dir')));
...

The first one has highest precedence. See http://expressjs.com/api.html for more info.

You can do it with phases too, inside your middleware.json (See docs):

"files": {
    "loopback#static": [{
        "name": "client",
        "paths": ["/client"],
        "params": "$!../client"
    },
    {
        "name": "someother",
        "paths": ["/someother"],
        "params": "$!../someother"
    }]
}
choise
  • 24,636
  • 19
  • 75
  • 131
superkhau
  • 2,781
  • 18
  • 9