'Cannot GET /' 在 NodeJS Express-Handlebars 中,要做什么?

'Cannot GET /' in NodeJS Express-Handlebars, What to do?

这是代码

const firebase = require('firebase-admin');
const express = require('express');
const exphbs = require('express-handlebars');

var hbsHelpers = exphbs.create({
    helpers: require("./helpers/handlebars.js").helpers,
    defaultLayout: '',
    extname: '.hbs'
});

const app = express();
app.engine('hbs', hbsHelpers.engine);
app.set('views', './views');
app.set('view engine', 'hbs');

app.get('/', (request, response) => {
    response.render('index.hbs');
});

exports.app = functions.https.onRequest(app);

terminal/logcat.

一切看起来都很完美,没有错误

但得到输出 'Cannot GET /'.

有人可以帮我解决这个问题吗?提前致谢。

如果您不指定您正在尝试获取的页面,则会出现此消息Cannot GET / . http://localhost:3000/ 在这种情况下。

我能够启动您的代码,但我不得不禁用一些我无法访问的 importexportfunction

// const firebase = require("firebase-admin");
const express = require("express");
const exphbs = require("express-handlebars");
const port = 3000;

// var hbsHelpers = exphbs.create({
//   helpers: require("./helpers/handlebars.js").helpers,
//   defaultLayout: "",
//   extname: ".hbs",
// });

const app = express();
app.engine("hbs", exphbs.engine());
app.set("views", "./views");
app.set("view engine", "hbs");

app.get("/", (req, res) => {
  res.render("index.hbs");
});

// exports.app = functions.https.onRequest(app);

app.listen(port, () => {
  console.log(`Server is  listening at http://localhost:${port}`);
});

文件夹和文件结构:


输出: