2017-03-02 44 views
0

我在使用Mailjet構建應用程序,並使用它們的連接示例。使用Mailjet引發混淆錯誤的Nodejs應用程序

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中的環境變量?

回答

2

您可以在~/.profile中設置環境變量。只讀用戶無法訪問工作空間目錄/home/ubuntu/workspace之外的文件,因此用戶將無法看到它們。

在終端,比如,你可以這樣做:

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

的亞軍(:

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

然後,你會使用connect方法時能夠訪問節點這些變量從「運行」按鈕),終端將評估〜/ .profile並使環境變量可用於您的應用程序。