2017-07-10 2 views
0

Google App Engineで保護されたURLでcronジョブに苦労しています。 ログイン:管理者app.yamlを追加すると、ジョブは開始できません(そうでない場合は、チャームのように機能します)。ここでGoogle App Engineのセキュリティで保護されたCronジョブが起動できない(ノードjs)

は私のコードです:

  • app.js

    const express = require('express'); 
     
    const app = express(); 
     
    
     
    app.get('/', (req, res) => { 
     
        res.status(200).send('Hello, world!').end(); 
     
    }); 
     
    
     
    app.get('/admin', function(req, res){ 
     
    \t res.status(200).send('Hello, admin!').end(); 
     
    }); 
     
    
     
    
     
    // Start the server 
     
    const PORT = process.env.PORT || 8080; 
     
    app.listen(PORT,() => { 
     
        console.log(`App listening on port ${PORT}`); 
     
        console.log('Press Ctrl+C to quit.'); 
     
    });

  • app.yamlを

    runtime: nodejs 
     
    env: flex 
     
    
     
    handlers: 
     
    - url:/
     
        script: app.js 
     
        
     
    - url: /admin 
     
        login: admin 
     
        script: app.js

  • cron.yaml

    cron: 
     
    - description: daily summary job 
     
        url: /admin 
     
        schedule: every 12 mins 
     
        target: default

そして結果: cron failure

私が行方不明です何上の任意のヒント?

事前のおかげ

答えて

0

でたくさんhandlerslogin設定は今のApp Engineの柔軟な環境のために推奨されていません。 https://cloud.google.com/appengine/docs/flexible/nodejs/upgrading

login: adminは、app.yamlから削除する必要があります。

コード内のX-Appengine-Cronヘッダーを確認しても、URLを保護できます。 docs

パー

app.get('/admin', function(req, res){ 
    if (req.get('X-Appengine-Cron') !== 'true') { 
     return res.status(401).end(); 
    } 
    res.status(200).send('Hello, admin!'); 
}); 

X-のAppEngine-cronのヘッダは、GoogleのApp Engineによって内部的に設定されています。要求ヘッダーがこのヘッダーを検出した場合、要求がcron要求であると信頼できます。ヘッダーがアプリケーションの外部ユーザー要求に存在する場合、ヘッダーはテスト目的のヘッダーを設定できるアプリケーションのログイン管理者からの要求を除いて取り除かれます。

関連する問題