【发布时间】:2021-08-11 17:53:18
【问题描述】:
我有一个从 GitHub 下载的应用程序,将其推送到 Heroku 后,它运行良好。但是,当我使用 heroku local 命令在本地运行它时,它会引发有关缺少配置变量的错误。
如何将这些配置文件下载到我的本地文件夹(我什至需要)?我是否需要手动创建一个.env 文件才能使其正常工作?
这是应用程序:
const assert = require('assert');
const Provider = require('oidc-provider');
assert(process.env.HEROKU_APP_NAME, 'process.env.HEROKU_APP_NAME missing');
assert(process.env.PORT, 'process.env.PORT missing');
assert(process.env.SECURE_KEY, 'process.env.SECURE_KEY missing, run `heroku addons:create securekey`');
assert.equal(process.env.SECURE_KEY.split(',').length, 2, 'process.env.SECURE_KEY format invalid');
// new Provider instance with no extra configuration, will run in default, just needs the issuer
// identifier, uses data from runtime-dyno-metadata heroku here
const oidc = new Provider(`https://${process.env.HEROKU_APP_NAME}.herokuapp.com`, {
clients: [
{
client_id: 'foo',
redirect_uris: ['https://jwt.io'], // using jwt.io as redirect_uri to show the ID Token contents
response_types: ['id_token'],
grant_types: ['implicit'],
token_endpoint_auth_method: 'none',
},
],
cookies: {
keys: process.env.SECURE_KEY.split(','),
},
});
// Heroku has a proxy in front that terminates ssl, you should trust the proxy.
oidc.proxy = true;
// listen on the heroku generated port
oidc.listen(process.env.PORT);
这是我在运行“heroku local”时遇到的错误:
3:44:57 AM web.1 | assert.js:383
3:44:57 AM web.1 | throw err;
3:44:57 AM web.1 | ^
3:44:57 AM web.1 | AssertionError [ERR_ASSERTION]: process.env.HEROKU_APP_NAME missing
3:44:57 AM web.1 | at Object.<anonymous> (C:\Users\hmffa\Desktop\my-provider\src\index.js:4:1)
3:44:57 AM web.1 | at Module._compile (internal/modules/cjs/loader.js:1063:30)
3:44:57 AM web.1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
3:44:57 AM web.1 | at Module.load (internal/modules/cjs/loader.js:928:32)
3:44:57 AM web.1 | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
3:44:57 AM web.1 | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
3:44:57 AM web.1 | at internal/main/run_main_module.js:17:47 {
3:44:57 AM web.1 | generatedMessage: false,
3:44:57 AM web.1 | code: 'ERR_ASSERTION',
3:44:57 AM web.1 | actual: undefined,
3:44:57 AM web.1 | expected: true,
3:44:57 AM web.1 | operator: '=='
3:44:57 AM web.1 | }
[DONE] Killing all processes with signal SIGINT
3:44:57 AM web.1 Exited with exit code null
【问题讨论】:
标签: node.js heroku heroku-cli