KeystoneJS 配置:错误请提供会话加密的 cookie 秘密值

KeystoneJS Configuration : Error Please provide a cookie secret value for session encryption

KeystoneJS 配置:错误请提供会话加密的 cookie 秘密值。 版本:4

我刚刚使用 keystone.js v4 创建。它正在连接到 MongoDB Cloud Atlas。我试图在 Heroku 上部署。但这是错误。

以下是 Heroku 日志的错误详细信息:

2021-11-18T15:53:06.601525+00:00 app[web.1]:
2021-11-18T15:53:06.601539+00:00 app[web.1]: KeystoneJS Configuration Error:
2021-11-18T15:53:06.601540+00:00 app[web.1]:
2021-11-18T15:53:06.601540+00:00 app[web.1]: Please provide a `cookie secret` value for session encryption.
2021-11-18T15:53:06.601541+00:00 app[web.1]:
2021-11-18T15:53:06.730461+00:00 heroku[web.1]: Process exited with status 1
2021-11-18T15:53:06.742844+00:00 heroku[web.1]: State changed from starting to crashed

Keystone.js 文件:

require("dotenv").config();

// Require keystone
var keystone = require("keystone");
var handlebars = require("express-handlebars");

keystone.init({
    name: "ABC",
    brand: "XYZ",

    sass: "public",
    static: "public",
    favicon: "public/favicon.ico",
    views: "templates/views",
    "view engine": ".hbs",
    "cloudinary config": process.env.CLOUDINARY_URL,
    "cookie secret": process.env.COOKIE_SECRET,
    "custom engine": handlebars.create({
        layoutsDir: "templates/views/layouts",
        partialsDir: "templates/views/partials",
        defaultLayout: "default",
        helpers: new require("./templates/views/helpers")(),
        extname: ".hbs",
    }).engine,

    "auto update": true,
    session: true,
    auth: true,
    "user model": "User",
});

// Load your project's Models
keystone.import("models");

// Setup common locals for your templates. The following are required for the
// bundled templates and layouts. Any runtime locals (that should be set uniquely
// for each request) should be added to ./routes/middleware.js
keystone.set("locals", {
    _: require("lodash"),
    env: keystone.get("env"),
    utils: keystone.utils,
    editable: keystone.content.editable,
});

// Load your project's Routes
keystone.set("routes", require("./routes"));

// Configure the navigation bar in Keystone's Admin UI
keystone.set("nav", {
    posts: ["posts", "post-categories"],
    galleries: "galleries",
    enquiries: "enquiries",
    users: "users",
});

// Start Keystone to connect to your database and initialize the webserver

keystone.start();

//CLOUD SERVER DATABASE
const mongoose = require("mongoose");
mongoose.connect(process.env.MONGO_URI, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
});

Please help me How to fix it?

您是否在 Heroku 仪表板中为 COOKIE_SECRET 变量设置了值?您收到的错误表明它未定义或空白。

Heroku 称这些为“配置变量”,参见 the docs