Skip to content

Cors headers are not properly set. #75

Description

@AdriVanHoudt

The problem is that atm we take over response handling (by returning h.abandon) which also means headers handling.
Doing cors handling ourselves would be a bit much, it would be nicer if we could just let hapi do that.

The proposed solution is to properly return/handle the transform streams we use back to hapi and then continue the lifecycle by returning h.continue.

For csv (works):

  • Set csvStream._readableState.objectMode = false; and don't pipe res
    • Quoting @kanongil (who helped a lot with these initial findings 🙏)

    It works because the implementation doesn't actually use objectMode for the output, and this is a way to change the mode for only that end

  • Set the headers on a headers property of the csvStream so that hapi will pick them up
  • Return csvStream

For Excel (not tested):

  • Pass a duplex stream to WorkbookWriter that has its readable side not in object mode
  • Set the headers on a headers property of the duplex stream so that hapi will pick them up
  • Pass the duplex stream to hapi

There is branch with tests and a working csv version here: https://github.com/Salesflare/hapi-csv/tree/cors-and-lifecycle-fix

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions