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

3

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"
  }
},
Celle answered 20/2, 2015 at 12:2 Comment(2)
Do you mean like yourdomain.com/custom-route/asset.jpg? You want to add a route in front of the static assets?Babbitt
yes. app.use() seems to work fine, but I'm trying to understand how to use middleware.json fullyCelle
C
6

You have to use paths property, i.e.

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

The detail is here.

Cirsoid answered 7/7, 2015 at 5:42 Comment(0)
M
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);
}
Matthias answered 9/7, 2015 at 3:33 Comment(0)
N
0

Did you try?

"files": {
  "loopback#static": {
    "params": "$!../../client"
  }
}
Nihil answered 26/6, 2015 at 0:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.