2016-09-28 4 views
1

現在、私はExpressルートをフォームで送信していますが、以下は切り捨てられた例です。最初のフォームはiframe内にあるので、http://example.com/endpointからの応答を受け取った後、親フレームをターゲットとするリンクを「署名」ページに送るiframeに返信します。Expressで機能を実行中にクライアントをリダイレクトする

残念ながら、http://example.com/endpointの応答時間がかなり長くなり、iframeがタイムアウトして応答が返されません。私がしたいのは、あるタイプの応答を直ちにiframeに送って、ページを「読み込み中のページ」にリダイレクトすることです。これは、ルータがhttp://example.com/endpointからの応答を待つ間に表示されます。

私はExpressを使用してiframeを含むページをユーザーに提供しています。すべてのビューはサーバー側で管理されています。

誰かが私に向かって指し示すことができるリソースがあるか、正しい方向に私を振る舞うものがあるかどうかは疑問だ。

router.post('/api/orders', function(req, res) { 

    var order = { 
     'model': req.body.model, 
     'options': optionsArray 
    } 

    request.post({ 
     url: 'http://example.com/endpoint, 
     body: order, 
     json: true 
    }, function(err, response, body) { 
     if (!error && response.statusCode === 200) { 
      if (!body.isCustom) { 
       hellosign.embedded.getSignUrl(body.signatureId) 
        .then(function(response) { 
         var signatureUrl = response.embedded.sign_url; 
         var resSignatureUrl = encodeURIComponent(signatureUrl); 
         res.send('<a href="http://' + req.headers.host + '/order/sign/' + body.orderNumber + '?url=' + resSignatureUrl + '" target="_parent">Click to sign</a>'); 
        }) 
        .catch(function(err) { 
         console.log(err); 
        }) 
      } else { 
       res.send('You selected custom options.'); 
      } 
     } 
     if (error || response.statusCode === 403) { 
      res.json({ 
       message: 'something went wrong with your order', 
       errorCode: response.statusCode, 
       errorMessage: body.message 
      }); 
     } 
    }); 
}); 
+0

サウンド:

だから、のようなものがある可能性があります。 https://github.com/Automattic/kueのようなもの – Matt

答えて

0

私はhellosign /それ以外の長時間実行しているAPI呼び出しを、自分のモジュールに配置します。それを個別にテストして、その動作を確認してください。

あなたのiframeか何か(本当にiframeが必要ですか?)は、hellosignモジュールから注文IDを取得する「開始注文」リクエストであるリクエストを送信します。次に、setIntervalなどを使用して、 'orderstatus'エンドポイントである新しいエンドポイントをチェックします。

orderstatusエンドポイントは、新しいhellosignモジュールにアクセスして注文のステータスを確認します。あなたは、ユーザーが照会またはポーリングジョブの状態のために、いつ完全な結果にリダイレクトすることができ、ジョブキューを必要とするよう

post('/start', function(req,res) { 
    var id = hellosign.startorder(req.body.model); 
    res.send(id); 
}); 

get('/status', function(req,res) { 
    res.send(hellosign.checkstatus(req.body.id)); 
} 


// hellosign.js 

var status = {}; 
exports.startorder = function(model) { 
    var id = uuid.v4(); // some unique id; 
    status[id] = 'started'; 
    request.post(api, /* ... */).then(function(signurl) { status[id] = signurl }); 
    return id; 
} 

exports.checkstatus = function(id) { 
    return status[id]; 
} 
関連する問題