首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用express-handlebars进行渲染时,req.next()不是一个函数

使用express-handlebars进行渲染时,req.next()不是一个函数
EN

Stack Overflow用户
提问于 2021-03-19 22:33:18
回答 1查看 132关注 0票数 0

我正在尝试呈现此web应用程序的登录页面。

它是由TypeScript + node.js +快递和快递车把制成的

这是我试图运行的代码

代码语言:javascript
复制
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时,我得到了这个错误:

代码语言:javascript
复制
    (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.

我试着自己找问题,但似乎找不到解决方案。

我很感谢你的每一点帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-20 02:31:21

在我的cookieAuth函数中,我调用了next()两次,这导致了这个错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66710153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档