我使用最新版本(新的 4.0)创建了一个 Strapi 应用程序,我想将其部署到 Heroku。为此,我确实遵循了 Strapi 文档,如本页中所述。现在我收到一个我不明白的错误,我猜它与 postgres 有关。这是错误
\n2021-12-18T15:26:26.658380+00:00 app[web.1]: [2021-12-18 15:26:26.656] debug: \xe2\x9b\x94\xef\xb8\x8f Server wasn\'t able to start properly.\n2021-12-18T15:26:26.659122+00:00 app[web.1]: [2021-12-18 15:26:26.658] error: Unknow dialect undefined\n2021-12-18T15:26:26.659123+00:00 app[web.1]: Error: Unknow dialect undefined\n2021-12-18T15:26:26.659123+00:00 app[web.1]: at getDialectClass (/app/node_modules/@strapi/database/lib/dialects/index.js:12:13)\n2021-12-18T15:26:26.659123+00:00 app[web.1]: at getDialect (/app/node_modules/@strapi/database/lib/dialects/index.js:19:23)\n2021-12-18T15:26:26.659124+00:00 app[web.1]: at new Database (/app/node_modules/@strapi/database/lib/index.js:38:20)\n2021-12-18T15:26:26.659124+00:00 app[web.1]: at Function.Database.init (/app/node_modules/@strapi/database/lib/index.js:84:33)\n2021-12-18T15:26:26.659125+00:00 app[web.1]: at Strapi.bootstrap (/app/node_modules/@strapi/strapi/lib/Strapi.js:347:30)\n2021-12-18T15:26:26.659125+00:00 app[web.1]: at Strapi.load (/app/node_modules/@strapi/strapi/lib/Strapi.js:410:16)\n2021-12-18T15:26:26.659125+00:00 app[web.1]: at async Strapi.start (/app/node_modules/@strapi/strapi/lib/Strapi.js:161:9)\nRun Code Online (Sandbox Code Playgroud)\n除了执行我链接的文档中解释的操作之外,我还使用开发模式下的 UI 添加了一些集合。如何修复此错误并将这个新的 4.0 版本的 Strapi 部署到 Heroku?
\nive*_*dee 15
当我在本地连接 pg 时,我遇到了类似的问题,然后意识到我的连接配置不正确。当我用 v4 模板替换它时,它起作用了。
小路: config/database.js
module.exports = ({ env }) => ({
defaultConnection: "default",
connection: {
client: "postgres",
connection: {
host: env("DATABASE_HOST", "localhost"),
port: env.int("DATABASE_PORT", 5432),
database: env("DATABASE_NAME", "bank"),
username: env("DATABASE_USERNAME", "postgres"),
password: env("DATABASE_PASSWORD", "0000"),
schema: env("DATABASE_SCHEMA", "public"),
},
}
});
Run Code Online (Sandbox Code Playgroud)
对于 Heorku,正如文章所建议的:
小路:config/env/production/database.js:
const parse = require('pg-connection-string').parse;
const config = parse(process.env.DATABASE_URL);
module.exports = ({ env }) => ({
connection: {
client: 'postgres',
connection: {
host: config.host,
port: config.port,
database: config.database,
user: config.user,
password: config.password,
ssl: {
rejectUnauthorized: false
},
},
debug: false,
},
});
Run Code Online (Sandbox Code Playgroud)
PS:确保pg-connection-string在推送到heroku之前添加依赖项
| 归档时间: |
|
| 查看次数: |
16396 次 |
| 最近记录: |