Shirakumo / radiance

A Common Lisp web application environment
https://shirakumo.github.io/radiance/
zlib License
311 stars 19 forks source link

Recommended way to add CORS headers to responses? #19

Closed Davidbhodge closed 6 years ago

Davidbhodge commented 6 years ago

For development purposes, i want to say something like (setf (header "Access-Control-Allow-Origin") "*") on all my responses.

At the moment i am doing this in each API and wonder if there is a configuration hook somewhere that I could use?

Cheers

Shinmera commented 6 years ago

The documentation doesn't list hooks-- I should fix that. Edit: fixed.

Anyway, there's a hook called request which is triggered when a request is executed, so something like this should do the trick:

(define-trigger radiance:request (request response)
  (setf (header "Access-Control-Allow-Origin" response) "*"))

There's no specific trigger for API calls, so you'd have to check the request for the required path if you wanted to limit the effect to that.

Davidbhodge commented 6 years ago

ok - sounds good, thanks for the help