summaryrefslogtreecommitdiff
path: root/dynamic/api.scm
diff options
context:
space:
mode:
Diffstat (limited to 'dynamic/api.scm')
-rw-r--r--dynamic/api.scm22
1 files changed, 19 insertions, 3 deletions
diff --git a/dynamic/api.scm b/dynamic/api.scm
index b53be8a..b899dc6 100644
--- a/dynamic/api.scm
+++ b/dynamic/api.scm
@@ -45,10 +45,26 @@
(define (main-request-handler request body)
"Server entry-point; parse `request' and defer to routing system."
+ (define (wrap-response response)
+ ;; This is either a response, or an alist of headers. The latter case is
+ ;; simple to handle, but the former requires us to do a (rather unweildy)
+ ;; copy of the response to inject our headers.
+ (if (response? response)
+ (build-response
+ #:version (response-version response)
+ #:code (response-code response)
+ #:reason-phrase (response-reason-phrase response)
+ #:headers (cons '(Access-Control-Allow-Origin . "*")
+ (response-headers response))
+ #:port (response-port response)
+ #:validate-headers? #t)
+ (cons '(Access-Control-Allow-Origin . "*") response)))
(let* ((path-encoded (uri-path (request-uri request)))
(path (split-and-decode-uri-path path-encoded)))
- (if (string= "api" (first path))
- (handle-api-request request body (drop path 1))
- (not-found request))))
+ (define-values (response body)
+ (if (string= "api" (first path))
+ (handle-api-request request body (drop path 1))
+ (not-found request)))
+ (values (wrap-response response) body)))
(run-server main-request-handler)