Fork me on GitHub
#pedestal
<
2019-05-30
>
ccann20:05:34

could anyone recommend a way to have the allowed-origins interceptor skip a particular route?

ddeaguiar20:05:35

@ccann, you have full control over what interceptors are added. Leveraging Pedestal’s default-interceptors impl should be considered a convenience and may not be suitable for some use cases. By setting the :io.pedestal.http/interceptors key on the service map you take full control over what interceptors are added when. If you do this, though, you’ll need to add the router interceptor yourself.

ccann20:05:15

okay yeah, thanks

ddeaguiar20:05:54

Or you can just add the allowed-origins interceptor yourself in your routes and skip specifying the allowed-origins in your service map

ddeaguiar20:05:08

the later is probably more confusing

ccann20:05:25

the problem I’m having that led me to ask the question is that for my health check route (a GET request) I’m getting a NPE from my allowed-origins function

ccann20:05:33

which is because there is no Origin header (i’m parsing the header with a regexp)

ccann20:05:47

because the health check is coming from an AWS server not a browser

ccann20:05:31

and apparently the pedestal cors interceptor calls the allowed-origins function before determining if the request type is :options https://github.com/pedestal/pedestal/blob/09dd88c4ce7f89c7fbb7a398077eb970b3785d2d/service/src/io/pedestal/http/cors.clj#L82

ddeaguiar20:05:03

Yep, the allow-origin interceptor is added prior to the router and it is within the router where method-based matching is done

ccann20:05:59

so I guess the “correct” behavior then for a missing Origin header is for the allowed-origins function to return truthy

ccann21:05:34

because a browser is going to send Origin, and that’s what CORS is concerned with. If a server or curl doesn’t specify an origin that’s outside the concern of CORS

ccann21:05:51

thinking out-loud here 🙂

ddeaguiar21:05:12

sounds reasonable

❤️ 4