如何使用Postgres插件将Strapi后端部署到Heroku?

时间:2020-08-16 19:41:33

标签: heroku strapi

我一直在使用Strapi官方教程,了解如何使用postgres将stradi部署到heroku,并且按照所有说明进行操作之后,我的heroku应用程序显示错误。但是,当我检查构建日志时,没有错误,它们显示了构建成功消息。

构建日志

{
    buffer_object obj; // has some name given by glGenBuffers; ready to use

    int const n = 3;
    std::array<buffer_object, n> foo; // each element has name 0
    glGenBuffers(n, foo.data()); // gives each element its own name
}
// everything destructed using buffer_object::~buffer_object

package.json依赖项

2020-08-17T15:48:19.744258+00:00 app[web.1]: npm ERR! 
2020-08-17T15:48:19.744486+00:00 app[web.1]: npm ERR! Failed at the radio-darya-backend@0.1.0 start script.
2020-08-17T15:48:19.744753+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-08-17T15:48:19.756754+00:00 app[web.1]: 
2020-08-17T15:48:19.757071+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2020-08-17T15:48:19.757252+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2020-08-17T15_48_19_747Z-debug.log
2020-08-17T15:48:19.825573+00:00 heroku[web.1]: Process exited with status 1
2020-08-17T15:48:19.869487+00:00 heroku[web.1]: State changed from starting to crashed
2020-08-17T15:48:32.221633+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=radio-darya-backend.herokuapp.com request_id=1bceee5d-4452-4b2a-9638-d5f242b4337c fwd="213.162.246.193" dyno= connect= service= status=503 bytes= protocol=https
2020-08-17T15:48:32.751425+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=radio-darya-backend.herokuapp.com request_id=95d4de1a-5f17-49e3-bed2-b459bce9259e fwd="213.162.246.193" dyno= connect= service= status=503 bytes= protocol=https

config database.js

  "devDependencies": {},
  "dependencies": {
    "knex": "<0.20.0",
    "pg": "^8.3.0",
    "sqlite3": "latest",
    "strapi": "3.1.4",
    "strapi-admin": "3.1.4",
    "strapi-connector-bookshelf": "3.1.4",
    "strapi-plugin-content-manager": "3.1.4",
    "strapi-plugin-content-type-builder": "3.1.4",
    "strapi-plugin-email": "3.1.4",
    "strapi-plugin-upload": "3.1.4",
    "strapi-plugin-users-permissions": "3.1.4",
    "strapi-utils": "3.1.4"
  },

4 个答案:

答案 0 :(得分:0)

您没有给出错误消息?
几周前,我确实将我的手铐部署到了heroku上,没有任何问题。
您确定您遵循了trapi文档中的所有步骤吗?
我唯一认为出错的是数据库连接。

首先,您必须在Heroku中安装postgress插件,然后获取config-info信息,最后在Heroku中添加环境变量(settings / config vars),还需要修改stripi config-files以从环境变量中获取数据库信息。 /> Strapi文档:https://strapi.io/documentation/3.0.0-beta.x/deployment/heroku.html

编辑:
目前Strapi文档不正确,database.json文件和位置已更改。参见:
strapi database.js / multiple database configs
https://www.youtube.com/watch?v=xNE0TrI5OKk

答案 1 :(得分:0)

我一天前刚刚完成了该教程...而且对于初学者来说,我也遇到了一些麻烦,例如stradi,postgres和heroku ...这是我的经验。

按照以下步骤获取postgres和数据库设置: https://tute.io/install-configure-strapi-postgresql

然后使用此处缺少的部分完成设置: https://strapi.io/documentation/v3.x/deployment/heroku.html

基本上: 在系统上本地安装postgres,创建数据库和用户并授予权限。 在不使用quickstart标志的情况下安装trapi,并使用上面使用的详细信息。 使用heroku cli设置从database_url configvar派生的配置。 提交和推送,一切都应该很好。

编辑: 在有关应用程序的Heroku中:

  • 单击设置并向下滚动到“环境变量”,然后单击“显示配置变量”
  • 确保您具有DATABASE_URL配置变量
  • 确保特定于Postgres的配置变量与DATABASE_URL匹配

例如DATABASE_URL = postgres:// ebitxebvixeeqd:dc59b16dedb3a1eef84d4999sb4baf@ec2-50-37-231-192.compute-2.amazonaws.com:5432 / d516fp1u21ph7b

  • 内容如下:postgres:// USERNAME:PASSWORD @ HOST:PORT:DATABASE_NAME

还要在您的./config/server.js文件中确保主机为0.0.0.0

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  admin: {
    auth: {
      secret: env('ADMIN_JWT_SECRET', '***********************'),
    },
  },
});

还将您的database.js配置更改为:

settings: {
    client: 'postgres',
    host: env('DATABASE_HOST', '127.0.0.1'),
    port: env.int('DATABASE_PORT', 5432),
    database: env('DATABASE_NAME', 'strapi'),
    username: env('DATABASE_USERNAME', 'postgres'),
    password: env('DATABASE_PASSWORD', ''),
    ssl: env.bool('DATABASE_SSL', false),
  },
  options: {}

您的问题或日志没有太多内容,但以上基本上是我所遇到的一些常见问题。

答案 2 :(得分:0)

这对我来说适用于v3.x stripi。

    // Path: ./config/env/production/database.js
    const parse = require('pg-connection-string').parse;
    const config = parse(process.env.DATABASE_URL);
    
    module.exports = ({ env }) => ({
      defaultConnection: 'default',
      connections: {
        default: {
          connector: 'bookshelf',
          settings: {
            client: 'postgres',
            host: config.host,
            port: config.port,
            database: config.database,
            username: config.user,
            password: config.password,
          },
          options: {
            ssl: false,
          },
        },
      },
    });

我们还需要将Heroku上的NODE_ENV变量设置为生产版本,以确保使用了这个新的数据库配置文件。

heroku config:set NODE_ENV=production

请参阅https://strapi.io/documentation/v3.x/deployment/heroku.html

请注意,此处是 v3.x ,而不是Beta版。谷歌的“ strapi heroku postgres”目前仍提供旧的Beta版本。

答案 3 :(得分:-1)

直接在config / database.js中复制此代码

module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client:'postgres',
host:`${process.env.DATABASE_HOST}`,
port: `${process.env.DATABASE_PORT}`,
database: `${process.env.DATABASE_NAME}`,
username: `${process.env.DATABASE_USERNAME}`,
password: `${process.env.DATABASE_PASSWORD}`, 
ssl: { "rejectUnauthorized": false }
},
options: {
},
},
},
});