BackendStack21/fast-gateway

support for formdata

Closed this issue · 2 comments

HoaX7 commented

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

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

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

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.