BackendStack21 / fast-gateway

Fast-gateway is an easy to use Node.js API gateway framework built to handle large scale API traffic with great performance and scalability. Written with JavaScript, it is a framework for the masses!
MIT License
311 stars 35 forks source link

support for formdata #67

Closed HoaX7 closed 2 years ago

HoaX7 commented 3 years ago

I wasn't able to forward formdata with or without files.

i also tried express parser with restana, that also didnt work.,.

jkyberneees commented 2 years ago

Hi @HoaX7, fast-proxy will forward low level requests as well. Are you using the body-parser middleware? This is a custom middleware I have used in the past to support multi-part requests:

const reqType = require('type-is')

  (req, res, next) => {
    if (!reqType.hasBody(req)) {
      req.headers['content-length'] = '0'
      req.body = undefined
    } else if (req.headers['content-type'] && req.headers['content-type'].startsWith('multipart/form-data')) {
      // proxy the request as is
      // please note that request stream can't be drained as this point
      req.body = undefined
    }
    next()
  }

Regards

HoaX7 commented 2 years ago

Yeah I just took the raw body and passed it to my service manually. I did it in a ugly way for time sake, I'll see if I can leverage using the snippet you provided me.