使用mysql数据库将strapi应用程序部署到google应用程序引擎失败,出现服务器500错误

zbwhf8kr  于 2021-10-10  发布在  Java
关注(0)|答案(0)|浏览(241)

我正在尝试使用cloud sql数据库部署我的strapi应用程序,我已经完成了提供的教程中的步骤:
https://strapi.io/documentation/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/google-app-engine.html
问题是,当使用“gcp build”部署应用程序时:“strapi build”成功完成,但当导航到网站的url时,会出现500个错误:
错误:服务器错误服务器遇到错误,无法完成您的请求。请在30秒后重试。
其他背景:
my app.yaml(已更改的数据库详细信息):

runtime: nodejs14

instance_class: F2

env_variables:
  HOST: '0.0.0.0'
  NODE_ENV: 'production'
  DATABASE_NAME:  'name'
  DATABASE_USERNAME: 'root'
  DATABASE_PASSWORD: 'password'
  INSTANCE_CONNECTION_NAME: 'instanceName'

beta_settings:
  cloud_sql_instances: 'instanceName'

我的数据库文件:

module.exports = ({ env }) => ({
  defaultConnection: "default",
  connections: {
    default: {
      connector: "bookshelf",
      settings: {
        client: "mysql",
        host:
          env("NODE_ENV") === "development"
            ? "127.0.0.1"
            : `/cloudsql/${env("INSTANCE_CONNECTION_NAME")}`,
        database: env("DATABASE_NAME"),
        username: env("DATABASE_USERNAME"),
        password: env("DATABASE_PASSWORD"),
      },
      options: {},
    },
  },
});

当我尝试使用“gcp build”部署应用程序时:“strapi build&&strapi start”会给出以下错误
注意:它试图连接到127.0.0.1:3306的数据库,因为它是开发服务器不知道为什么!!

Beginning deployment of service [default]...

# ============================================================#

# = Uploading 1 file to Google Cloud Storage                 =#

# ============================================================#

File upload done.
Updating service [default]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build ea12c6f6-e173-4c75-af51-0e0a330ba229 status: FAILURE
Error ID: 617e6b41
Error type: UNKNOWN
Error message: > seth-backend@0.1.0 gcp-build /workspace
> strapi build && strapi start

Building your admin UI with development configuration ...
\u2139 Compiling Webpack
\u2714 Webpack: Compiled successfully in 1.83m
[2021-07-01T16:56:44.111Z] debug \u26d4\ufe0f Server wasn't able to start properly.
[2021-07-01T16:56:44.112Z] error Error: connect ECONNREFUSED 127.0.0.1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
    --------------------
    at Protocol._enqueue (/workspace/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/workspace/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/workspace/node_modules/mysql/lib/Connection.js:116:18)
    at /workspace/node_modules/knex/lib/dialects/mysql/index.js:68:18
    at new Promise (<anonymous>)
    at Client_MySQL.acquireRawConnection (/workspace/node_modules/knex/lib/dialects/mysql/index.js:63:12)
    at create (/workspace/node_modules/knex/lib/client.js:290:39)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! seth-backend@0.1.0 gcp-build: `strapi build && strapi start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the seth-backend@0.1.0 gcp-build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /builder/home/.npm/_logs/2021-07-01T16_56_44_132Z-debug.log
Suggested improvements or fixes
-update the documentation to the new versions of the app and node

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题