所以我在我的仓库中有一个我正在处理的react / typescript应用程序,在我的仓库中有一个.env文件,我忽略了它,这样我的秘密就不会暴露了。重要的.env-example文件环境变量进行配置。我的问题是,由于我没有将.env文件推送到我的存储库中,因此当我通过Google App引擎部署应用程序时(这是在gitlab-ci.yml文件的部署阶段完成的),这些环境变量会在生产环境中不存在,我需要它们才能使我的应用程序正常工作,因为我在webpack.config.js文件中执行了类似的操作。
const dotenv = require('dotenv').config({ path: __dirname + '/.env' });
Run Code Online (Sandbox Code Playgroud)
然后
new webpack.DefinePlugin({
'process.env': dotenv.parsed
})
Run Code Online (Sandbox Code Playgroud)
这是我的.gitlab-ci文件,以防万一有人在这里看到。
cache:
paths:
- node_modules/
stages:
- build
- test
- deploy
Build_Site:
image: node:8-alpine
stage: build
script:
- npm install --progress=false
- npm run-script build
artifacts:
expire_in: 1 week
paths:
- build
Run_Tests:
image: node:8-alpine
stage: test
script:
- npm install --progress=false
- npm run-script test
Deploy_Production:
image: google/cloud-sdk:latest
stage: deploy
environment: Production
only: …Run Code Online (Sandbox Code Playgroud) 我一直在尝试将char数组正确转换为long strtol,检查是否存在溢出或下溢,然后对long进行int转换.一路上,我注意到很多代码看起来像这样
if ((result == LONG_MAX || result == LONG_MIN) && errno == ERANGE)
{
// Handle the error
}
Run Code Online (Sandbox Code Playgroud)
为什么你不能只说
if(errno == ERANGE)
{
// Handle the error
}
Run Code Online (Sandbox Code Playgroud)
根据我的理解,如果发生下溢或溢出,则在两种情况下都将errno设置为ERANGE.前者真的有必要吗?可以单独检查ERANGE是否有问题?
这就是我的代码现在的样子
char *endPtr;
errno = 0;
long result = strtol(str, &endPtr, 10);
if(errno == ERANGE)
{
// Handle Error
}
else if(result > INT_MAX || result < INT_MIN)
{
// Handle Error
}
else if(endPtr == str || *endPtr != '\0')
{
// Handle Error
}
num = …Run Code Online (Sandbox Code Playgroud)