gpt4 book ai didi

javascript - 谷歌应用引擎: Modify Cloud Run Environment

转载 作者:太空宇宙 更新时间:2023-11-04 01:31:47 25 4
gpt4 key购买 nike

我正在尝试部署一个使用自定义 Node.js 服务器的 Next.js 应用程序。

我想将自定义构建变量注入(inject)应用程序:

next.config.js

const NODE_ENV = process.env.NODE_ENV;
const envType = NODE_ENV === `production` ? `production` : `staging`;

const envPath = `./config/${envType}`;
const { env } = require(envPath);

module.exports = {
env: { ...env },
};

上述文件在构建时运行(yarn build)。

问题在于 Google App Engine 在幕后使用 Cloud Build。在那里,NODE_ENV 始终设置为development。我怎样才能覆盖那里的NODE_ENV;即如何自定义用于 Google App Engine gcloud 应用程序部署 的 Cloud Build?

我不能只使用 Docker,因为 this issue

package.json

{
"name": "blah",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "NODE_ENV=staging node server.js",
"build": "rm -rf node_modules/ && yarn && rm -rf .next/ && next build",
"start": "node server.js",
"lint": "eslint . --ext .js",
"gcp-build": "yarn build"
},
"dependencies": {
"body-parser": "^1.18.3",
"dotenv": "^7.0.0",
"dotenv-webpack": "^1.7.0",
"express": "^4.16.4",
"express-session": "^1.16.1",
"firebase": "^5.10.0",
"firebase-admin": "^7.3.0",
"isomorphic-unfetch": "^3.0.0",
"lodash": "^4.17.11",
"next": "^8.1.0",
"now": "^15.0.6",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"session-file-store": "^1.2.0",
"styled-components": "^4.2.0",
"yenv": "^2.1.0"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4"
},
"engines": {
"node": "10.x.x"
}
}

app.yaml

runtime: nodejs10

图像

下面是从 app.yaml 传递 DOGE_ENV 变量的输出。如您所见,它是未定义。但是,NODE_ENV 正在开发

也就是说,将以下内容添加到 app.yaml 不起作用。

env_variables:
DOGE_ENV: production

enter image description here

最佳答案

不要使用 NODE_ENV,创建您自己的环境变量并使用它:

App.yaml

env_variables:
ST_ENV: Production

next.config.js

const environment = process.env.ST_ENV;
const envType = environment === `production` ? `production` : `staging`;

const envPath = `./config/${envType}`;
const { env } = require(envPath);

module.exports = {
env: { ...env },
};

关于javascript - 谷歌应用引擎: Modify Cloud Run Environment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55892795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com