如何使用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 ,我的意思是在localhost
input显示404 catch-all路由。 是的,这是localhost
,而不是localhost:3000
。 它正在80端口工作。
- 将中间件添加到middleware.json中的files属性中
- 删除服务器/ boot / root.js。
- 创build客户端/ index.html
- 通过slc运行启动服务器并浏览到localhost:3000
我在这里维护这个用例的完整示例: https : //github.com/strongloop/loopback-faq-middleware#how-do-you-serve-static-content-via-static-middleware
让我知道你是否需要帮助。 ;)