0

我正在使用 Mailjet 构建一个应用程序,并使用他们的连接示例。

app.get('/send',function(req,res){
...        
    var request = mailjet
            .post("send")
            .request({
                <request stuff, email details>
            });
        request
            .on('success', function (response, body) {
                <handle response>
            })
            .on('error', function (err, response) {
                <handle error>
            });

收到此错误:

Unhandled rejection Error: Unsuccessful
    at /home/ubuntu/workspace/node_modules/node-mailjet/mailjet-client.js:203:23

当我去 Mailjet 客户端并要求它记录错误时,它告诉我:

{ [Error: Unauthorized]
  original: null,
  ...

任何人都知道我应该从哪里开始进行故障排除?

更新:在错误输出中看到了这一点:

header: 
  { server: 'nginx',
    date: 'Thu, 02 Mar 2017 14:04:11 GMT',
    'content-type': 'text/html',
    'content-length': '20',
    connection: 'close',
    'www-authenticate': 'Basic realm="Provide an apiKey and secretKey"',
    vary: 'Accept-Encoding',
    'content-encoding': 'gzip' },

所以它不会吃掉我的 API 密钥和秘密。谁能告诉我如何在 Cloud9 中将它们设置为环境变量?

4

1 回答 1

2

您可以在~/.profile. /home/ubuntu/workspace只读用户无法访问工作区目录之外的文件,因此人们将无法看到它们。

在终端中,您可以执行以下操作:

$> echo "export MAILJET_PUBLIC=foo" >> ~/.profile
$> echo "export MAILJET_SECRET=bar" >> ~/.profile

然后,您将能够在使用该connect方法时访问 Node 中的这些变量:

const mailjet = require ('node-mailjet')
  .connect(process.env.MAILJET_PUBLIC, process.env.MAILJET_SECRET)

跑步者(来自“运行”按钮)和终端将评估 ~/.profile 并使环境变量可用于您的应用程序。

于 2017-03-03T11:08:08.303 回答