req.next() 在使用 express-handlebars 渲染时不是函数
req.next() is not a function when rendering with express-handlebars
我正在尝试呈现此网络应用程序的登录页面。
它是用 TypeScript + node.js + express 和 express-handlebars 制作的
这是我正在尝试的代码运行
import exphbs = require("express-handlebars");
import cookieParser = require("cookie-parser");
import express from "express";
import { cookieAuth } from "./auth";
const app = express();
app.engine(
"hbs",
exphbs({
extname: "hbs",
layoutsDir: __dirname + "/views/pages/",
partialsDir: __dirname + "/views/partials/"
})
);
app.use(cookieParser());
app.use(express.static("public"));
app.set("view engine", "hbs");
app.set("views", path.join(__dirname, "views"));
app.get("/login", cookieAuth, (req, res) => {
res.render("login");
});
app.get("/", cookieAuth, (req: any, res) => {
if (req.asmuser == null) res.redirect("/login");
});
app.listen(3000);
现在,当我尝试访问 / 或 /login 时,出现此错误:
(node:9508) UnhandledPromiseRejectionWarning: TypeError: req.next is not a function
at done (D:\antisocialmedianv2\node_modules\express\lib\response.js:1007:25)
at ExpressHandlebars.renderView (D:\antisocialmedianv2\node_modules\express-handlebars\lib\express-handlebars.js:237:4)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9508) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9508) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我尝试自己找出问题,但似乎无法找到解决方案。
感谢您的每一点帮助。
在我的 cookieAuth 函数中,我调用了 next() 两次导致了这个错误。
我正在尝试呈现此网络应用程序的登录页面。
它是用 TypeScript + node.js + express 和 express-handlebars 制作的
这是我正在尝试的代码运行
import exphbs = require("express-handlebars");
import cookieParser = require("cookie-parser");
import express from "express";
import { cookieAuth } from "./auth";
const app = express();
app.engine(
"hbs",
exphbs({
extname: "hbs",
layoutsDir: __dirname + "/views/pages/",
partialsDir: __dirname + "/views/partials/"
})
);
app.use(cookieParser());
app.use(express.static("public"));
app.set("view engine", "hbs");
app.set("views", path.join(__dirname, "views"));
app.get("/login", cookieAuth, (req, res) => {
res.render("login");
});
app.get("/", cookieAuth, (req: any, res) => {
if (req.asmuser == null) res.redirect("/login");
});
app.listen(3000);
现在,当我尝试访问 / 或 /login 时,出现此错误:
(node:9508) UnhandledPromiseRejectionWarning: TypeError: req.next is not a function
at done (D:\antisocialmedianv2\node_modules\express\lib\response.js:1007:25)
at ExpressHandlebars.renderView (D:\antisocialmedianv2\node_modules\express-handlebars\lib\express-handlebars.js:237:4)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9508) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:9508) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
我尝试自己找出问题,但似乎无法找到解决方案。
感谢您的每一点帮助。
在我的 cookieAuth 函数中,我调用了 next() 两次导致了这个错误。