realm / realm-object-server

Tracking of issues related to the Realm Object Server and other general issues not related to the specific SDK's
https://realm.io
293 stars 42 forks source link

Unable to override body-parser settings #320

Closed Dids closed 6 years ago

Dids commented 6 years ago

Goals

I'm trying to increase the upload size of POST and PUT requests in a custom Service, so using the built-in express app of ROS.

Expected Results

I should be able to override body-parser settings, so I could upload larger payloads.

Actual Results

Overriding body-parser settings has zero effect.

Steps to Reproduce

Try to add/use a modified express body-parser, then upload a file or JSON content larger than 10k characters (or roughly 1 MB, I'm assuming).

Server response:

{"title":"request entity too large","status":413}

Code Sample

...
this.middlewares.push(bodyParser.json({ limit: '50mb' }))
this.middlewares.push(bodyParser.urlencoded({ extended: true, limit: '50mb', parameterLimit: 50000 }))
...
return this.server.start({
  ...
  middlewares: this.middlewares
})
...

NOTE: I've also tried to override the middlewares after startup, using this.server.expressApp.use(), but that produces the same exact results.

Version of Realm and Tooling

Logs

Nothing is generated in the logs (even with log level set to all).

Dids commented 6 years ago

Commenting out line 117 in Server.js "fixes" the issue, as it looks like the body-parser added by ROS takes precedence.

Dids commented 6 years ago

As a temporary workaround, I'm removing the ROS added body-parser after startup, like so:

for (let i in this.server.expressApp._router.stack) {
  let layer = this.server.expressApp._router.stack[i]
  if (layer.name === 'jsonParser') {
    this.server.expressApp._router.stack.splice(i, 1)
    break
  }
}
Dids commented 6 years ago

@nirinchev Was this implemented? Or not going to be implemented at all?

nirinchev commented 6 years ago

Sorry - it's in a private repo, which is why I guess Github didn't create a publicly visible comment. It was implemented and will be released with the next version. You'll be able to control it by setting:

server.start({
  // Other options
  jsonBodyLimit: '10mb'
})
Dids commented 6 years ago

@nirinchev I'm assuming this has been released now, since ROS was recently updated on npm?

nirinchev commented 6 years ago

It is, yes - it shipped with 2.5.0: https://github.com/realm/realm-object-server/blob/master/CHANGELOG.md#enhancements-1