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

徘徊边缘 提交于 2021-02-07 02:53:59

问题


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"
  }
},

回答1:


You have to use paths property, i.e.

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

The detail is here.




回答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);
}



回答3:


Did you try?

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


来源:https://stackoverflow.com/questions/28628535/strongloop-loopback-how-do-i-serve-static-with-a-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!