如何使用Postgres插件将Strapi后端部署到Heroku? [英] How to deploy Strapi backend to Heroku with Postgres addon?

查看:123
本文介绍了如何使用Postgres插件将Strapi后端部署到Heroku?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been using the official Strapi tutorial on how to deploy strapi to heroku with postgres and after following all the instructions, my heroku app is showing an error. However when I check the build logs, there are no errors and they show the build successful message.

构建日志

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

package.json依赖项

package.json dependencies

  "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"
  },

config database.js

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: {
       
      },
    },
  },
});
her

推荐答案

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

ive just completed that tutorial a day ago... and i also had problems for a complete beginner to strapi and postgres and heroku... heres my experience.

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

follow along here to get postgres and the database setup: https://tute.io/install-configure-strapi-postgresql

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

then complete your setup with the missing pieces from here: https://strapi.io/documentation/v3.x/deployment/heroku.html

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

basically: have postgres installed locally on your system, create the db and user and grant permissions. install strapi without the quickstart flag and use the details that was used above. use the heroku cli to set the configs derived from the database_url configvar. commit and push and all should be well.

在有关应用程序的Heroku中:

In Heroku under the app in question:

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

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

eg. 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

Also in your ./config/server.js file make sure your host is 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配置更改为:

Also change your database.js config to be:

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: {}

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

Theres no much to go on from your question or the logs, but the above is basically some common issues ive experienced.

这篇关于如何使用Postgres插件将Strapi后端部署到Heroku?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆