Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strongloop loopback how do I serve-static with a route?

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"
  }
},
like image 438
michael Avatar asked Feb 20 '15 12:02

michael


2 Answers

You have to use paths property, i.e.

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

The detail is here.

like image 148
imbolc Avatar answered Nov 14 '22 22:11

imbolc


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);
}
like image 22
ivan Avatar answered Nov 14 '22 22:11

ivan