7

I want to do something like

// server.js
app.use('/client', loopback.static(__dirname + '/../client'))

using middleware.json, but the example only works from the root

"files": {
  "loopback#static": {
    "params": "$!../client"
  }
},
michael
  • 4,377
  • 8
  • 47
  • 73
  • Do you mean like `yourdomain.com/custom-route/asset.jpg`? You want to add a route in front of the static assets? – superkhau Feb 20 '15 at 22:04
  • 2
    yes. app.use() seems to work fine, but I'm trying to understand how to use middleware.json fully – michael Feb 22 '15 at 09:44

3 Answers3

6

You have to use paths property, i.e.

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

The detail is here.

niksvp
  • 5,545
  • 2
  • 24
  • 41
imbolc
  • 1,620
  • 1
  • 19
  • 32
2

I created a new file boot/routes.js

var path    = require("path");

module.exports = function(app) {
  app.get('/ping', function(req, res) {
     res.sendFile(pt('client/index.html'));
   });
};

function pt(relative) {
  return path.resolve(__dirname, '../..', relative);
}
ivan
  • 48
  • 5
0

Did you try?

"files": {
  "loopback#static": {
    "params": "$!../../client"
  }
}
Hayk
  • 109
  • 6