【发布时间】:2021-10-27 17:30:28
【问题描述】:
我遇到了一个问题,当我将 Mailgun 上传到 Heroku 时,它没有看到 apiKey。我在代码顶部设置了环境变量和 dotenv,但它仍然返回错误。我有什么遗漏吗?
- 在我的 app.js 中
require('dotenv').config();
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const app = express();
// MAILGUN INFO
let api_key = process.env.MAILGUN_API_KEY
let domain = process.env.DOMAIN
var mailgun = require('mailgun-js')({apiKey: api_key, domain: domain});
//DATA PARSING AND VIEW ENGINE
app.use(express.static("public"));
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.set("view engine", 'ejs');
- 我的 dotenv 信用卡
MAILGUN_API_KEY=******************************
DOMAIN=*********.com
- 日志中返回错误
2021-08-27T20:07:53.000000+00:00 app[api]: Build succeeded
2021-08-27T20:07:58.685692+00:00 heroku[web.1]: Starting process with command `node app.js`
2021-08-27T20:08:00.618937+00:00 app[web.1]: /app/node_modules/mailgun-js/lib/mailgun.js:16
2021-08-27T20:08:00.618949+00:00 app[web.1]: throw new Error('apiKey value must be defined!')
2021-08-27T20:08:00.618949+00:00 app[web.1]: ^
2021-08-27T20:08:00.618949+00:00 app[web.1]:
2021-08-27T20:08:00.618950+00:00 app[web.1]: Error: apiKey value must be defined!
2021-08-27T20:08:00.618950+00:00 app[web.1]: at new Mailgun (/app/node_modules/mailgun-js/lib/mailgun.js:16:13)
2021-08-27T20:08:00.618950+00:00 app[web.1]: at create (/app/node_modules/mailgun-js/lib/mailgun.js:239:10)
2021-08-27T20:08:00.618950+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:11:36)
2021-08-27T20:08:00.618951+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2021-08-27T20:08:00.618951+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2021-08-27T20:08:00.618952+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:928:32)
2021-08-27T20:08:00.618952+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:769:14)
2021-08-27T20:08:00.618952+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
2021-08-27T20:08:00.618953+00:00 app[web.1]: at internal/main/run_main_module.js:17:47
2021-08-27T20:08:00.666412+00:00 heroku[web.1]: Process exited with status 1
2021-08-27T20:08:00.719053+00:00 heroku[web.1]: State changed from starting to crashed
【问题讨论】:
标签: node.js heroku error-handling mailgun