简体   繁体   English

node.js-KOA服务器-Foward扩充POST请求

[英]node.js - KOA server- Foward augmented POST request

So I was looking for a while now for a simple solution for this but couldn't find anything clear. 因此,我一直在寻找一种简单的解决方案,但找不到任何明确的解决方案。

My goal is to receive HTTP Post request from html form to my KOA server and forward it to remote API. 我的目标是从html表单接收HTTP Post请求到我的KOA服务器,并将其转发到远程API。

As you can understand from the question, I'm complete beginer for not being able to do this, but my code so far looks like this: 从问题中可以理解,我是无法完成此工作的初学者,但是到目前为止我的代码如下:

var koaBody = require('koa-body')()
publicRouter.post('/file', koaBody,
    function *(next) {
      var post = this.request.body
      console.log(post)
      // augment post

    }
)

Currently I'm able to receive file to the server and I do want to learn what should I add in comment line (I assume there) in order to augment post request with additional data, such as keys, signatures and content-type details. 目前,我能够将文件接收到服务器,并且我想了解我应该在注释行中添加什么(我假设在其中),以便使用诸如键,签名和内容类型详细信息之类的其他数据来扩大发布请求。

So first of all, how should I create this augmented POST? 因此,首先,我应该如何创建此增强的POST?

And how to forward it? 以及如何转发它? I assume for that I can use promises (Q.denodeify(require('request'))), like I have been able to do it with GET request 我假设我可以使用诺言(Q.denodeify(require('request'))),就像我已经能够使用GET请求一样

Use co-request ( here ) to send make remote API calls. 使用co-request此处 )发送远程API调用。

var request = require('co-request');
var koaBody = require('koa-body')();
publicRouter.post('/file', koaBody,
    function *(next) {
      var post = this.request.body
      console.log(post)
      yield request({
         url: '/some/remote/api',
         method: 'POST',
         body: body
      });
    }
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM