From 5104c2a79f698bd359adc4d7c32ab9232c9c05b0 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 14 Jul 2023 19:11:32 +0200 Subject: [PATCH] portalapi: add CORS headers ... though gotta revisit this later, I don't know what I'm doing --- conf/nginx/yunohost_api.conf.inc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/conf/nginx/yunohost_api.conf.inc b/conf/nginx/yunohost_api.conf.inc index b4567e0b8..a3a23f1a9 100644 --- a/conf/nginx/yunohost_api.conf.inc +++ b/conf/nginx/yunohost_api.conf.inc @@ -25,12 +25,25 @@ location = /yunohost/api/error/502 { } location /yunohost/portalapi/ { - proxy_read_timeout 3600s; + + # FIXME FIXME FIXME : we should think about what we really want here ... + more_set_headers "Access-Control-Allow-Origin: $http_origin"; + more_set_headers "Access-Control-Allow-Methods: GET, HEAD, POST, OPTIONS, DELETE"; + more_set_headers "Access-Control-Allow-Headers: Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With"; + more_set_headers "Access-Control-Allow-Credentials: true"; + + if ($request_method = 'OPTIONS') { + more_set_headers "Content-Type: text/plain; charset=utf-8"; + more_set_headers "Content-Length: 0"; + return 204; + } + + proxy_read_timeout 5s; proxy_pass http://127.0.0.1:6788/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; - proxy_set_header Host $http_host; + proxy_set_header Host $http; # Custom 502 error page error_page 502 /yunohost/portalapi/error/502;