gpt4 book ai didi

javascript - 如何使用 StrongLoop 在 Node.js 中提供动态内容?

转载 作者:行者123 更新时间:2023-11-30 06:53:08 25 4
gpt4 key购买 nike

我是 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 显示 404 catch-all 路由。是的,那是 localhost,而不是 localhost:3000。它在端口 80 上工作。

最佳答案

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

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

如果您需要更多帮助,请告诉我。 ;)

关于javascript - 如何使用 StrongLoop 在 Node.js 中提供动态内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28534766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com