如何使用StrongLoop在Node.js中提供dynamic内容?

我对Node.js很新,但是StrongLoop Docs并没有给出具体的例子。 我为我的模板使用Handlebars,而只是试图提供一个标准的index.js预编译模板。 我知道我应该编辑我的routes.js文件,但我不知道该怎么做。

这是我的routes.js文件看起来像:

 module.exports = function(app) { // I need this to serve my index.js file. app.get('/', function(req, res) { // Doesn't work, so I commented it out: // require('views/index.js'); // Doesn't work, so I commented it out: // res.requires('views/index.js'); // Doesn't work, so I commented it out: // res.send('views/index.js'); // What do I put here then? }); // This is the generic example. Just sends text. app.get('/ping', function(req, res) { res.send('pong'); }); }; 

只是为了澄清,当我说这是行不通的TM ,我的意思是在localhostinput显示404 catch-all路由。 是的,这是localhost ,而不是localhost:3000 。 它正在80端口工作。

  1. 将中间件添加到middleware.json中的files属性中
  2. 删除服务器/ boot / root.js。
  3. 创build客户端/ index.html
  4. 通过slc运行启动服务器并浏览到localhost:3000

我在这里维护这个用例的完整示例: https : //github.com/strongloop/loopback-faq-middleware#how-do-you-serve-static-content-via-static-middleware

让我知道你是否需要帮助。 ;)