From 81f39d238fa141b49f50bbf855a9ce61d2f3de5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sun, 17 Aug 2025 23:38:37 +0300 Subject: [PATCH] overcome CORS --- api/srv.consult.js | 16 +++++++++++++++- nginx/cfg | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/api/srv.consult.js b/api/srv.consult.js index 0f35362..607a681 100644 --- a/api/srv.consult.js +++ b/api/srv.consult.js @@ -7,7 +7,6 @@ let TEMPLATE_FILE_NAME = "%DIR%/consult_%UUID%"; let URL_CONSULT = "/api/consult"; let srv = http.createServer((req, res) => { - // POST if (req.method == "POST") { var dat = ""; req.on("data", (chunk) => { @@ -22,6 +21,8 @@ let srv = http.createServer((req, res) => { returnError(res); } }); + } else if (req.method == "OPTIONS") { + returnNoCORS(res); } else { returnError(res); } @@ -58,6 +59,19 @@ function returnError(res) { `); } +function returnNoCORS(res) { + res.writeHead( + 204, + { + "Access-Control-Allow-Headers": "Content-Type", + "Access-Control-Allow-Origin": "*", + "Content-Length": "0", + "Content-Type": "text/plain;charset=UTF-8", + } + ); + res.end(); +} + function returnSuccess(res) { res.writeHead(200, { "Content-Type": "application/json;charset=UTF-8" }); let dat = { code: 4 }; diff --git a/nginx/cfg b/nginx/cfg index e141283..079181e 100644 --- a/nginx/cfg +++ b/nginx/cfg @@ -34,7 +34,7 @@ server { if ($request_method = "OPTIONS") { add_header "Access-Control-Allow-Origin" "*"; add_header "Access-Control-Allow-Headers" "Content-Type"; - add_header "Content-Type" "text/plain charset=UTF-8"; + add_header "Content-Type" "text/plain;charset=UTF-8"; add_header "Content-Length" 0; return 204; }