Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server does not respond to CORS preflight requests #1

Open
ghost opened this issue Nov 27, 2017 · 3 comments
Open

Server does not respond to CORS preflight requests #1

ghost opened this issue Nov 27, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Nov 27, 2017

First of all: Thanks for this project!

I had to adapt your code in order to make it work with a browser which does preflight requests to check CORS. I've added the following to make it work:

server.route({
      method: 'OPTIONS',
      path: options.uploadRoute,
      handler: (req, h) => h
        .response()
        .header('Access-Control-Allow-Headers', req.headers['access-control-request-headers']),
      config: {
        cors: {
          origin: [ '*' ],
        },
      }
    });

As I'm not an expert on http file upload, I can't say if that code covers the general case. It worked for me..

@trading-peter
Copy link
Owner

Interesting. Can you tell which browser is effected? I'd like to investigate further.

@ghost
Copy link
Author

ghost commented Nov 28, 2017

In my case: Chrome 62.0 and Safari 11.0

and I'm making a request from localhost:3000 to localhost:8989 (that's why the preflight request takes place)

The preflight request/response looks like this:

image

Afterwards it's followed by the actual POST request

@trading-peter
Copy link
Owner

Thanks for the additional details. Strange enough the upload server should be fine out of the box with preflight request. I just saw that the syntax that you posted stems from hapi 17.
I hope to upgrade the server to hapi 17 soon, then your snippet should come in handy. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant