Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Fix CORS redirects in noms serve #3617

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

kalman
Copy link
Contributor

@kalman kalman commented Aug 15, 2017

The httprouter was HTTP-redirecting paths like graphql to graphql/ which
isn't CORS-compatible. This patch just hard-codes the trailing and
non-trailing slash versions of each handler path.

The httprouter was HTTP-redirecting paths like graphql to graphql/ which
isn't CORS-compatible. This patch just hard-codes the trailing and
non-trailing slash versions of each handler path.
@kalman kalman requested a review from a user August 15, 2017 19:36
@kalman
Copy link
Contributor Author

kalman commented Aug 15, 2017

@rafael-atticlabs ptal
@ehalpern fyi

I looked at httprouter and I didn't see a better way of doing this.

@kalman
Copy link
Contributor Author

kalman commented Aug 15, 2017

I.e. before patch:

screen shot 2017-08-15 at 12 38 42 pm

@kalman
Copy link
Contributor Author

kalman commented Aug 15, 2017

(adding the trailing / i.e. graphql => graphql/ fixes it)

@ghost ghost requested review from arv and removed request for a user August 15, 2017 20:14
@ghost
Copy link

ghost commented Aug 15, 2017

I think @arv is a better person to review.

@ghost ghost closed this Aug 15, 2017
@ghost ghost reopened this Aug 15, 2017
router.POST(strings.TrimSuffix(path, "/"), s.corsHandle(s.makeHandle(hndlr)))
}
}
post(constants.BasePath, HandleBaseGet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did HandleBaseGet change to POST?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops...

@arv
Copy link
Contributor

arv commented Aug 15, 2017

Maybe disable RedirectTrailingSlash instead?

https://godoc.org/github.com/julienschmidt/httprouter#Router.RedirectTrailingSlash

@kalman
Copy link
Contributor Author

kalman commented Aug 15, 2017

This patch does also disable RedirectTrailingSlash. But without adding it back manually, that would be backwards incompatible.

@arv
Copy link
Contributor

arv commented Aug 15, 2017

Do we really want to support both?

router.OPTIONS(constants.GraphQLPath, s.corsHandle(noopHandle))
// Note: we implement trailing trailing-slash removal ourselves because
// httprouter doesn't handle the redirects properly with CORS.
router := httprouter.Router{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes more things than RedirectTrailingSlash. Maybe use New and then set RedirectTrailingSlash instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the options and having them all seems correct to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All false, I mean.

See https://github.com/julienschmidt/httprouter/blob/master/router.go#L170

  • We don't want any of the Redirect options (they're all CORS incompatible).
  • HandleMethodNotAllowed is weird
  • HandleOPTIONS is irrelevant since we implement our own

@kalman
Copy link
Contributor Author

kalman commented Aug 15, 2017

Do we really want to support both?

Yes I believe so.

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

Successfully merging this pull request may close these issues.

None yet

2 participants