Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add multiple dir for static files in Loopback

Tags:

loopbackjs

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?

like image 554
Lee Avatar asked Feb 25 '15 21:02

Lee


1 Answers

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"
    }]
}
like image 71
superkhau Avatar answered Nov 16 '22 06:11

superkhau