From 4b6b04189a8483415da9b87602f184573197dcb6 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Thu, 5 Dec 2024 19:56:48 +0200 Subject: CORS consideration --- server/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'server') diff --git a/server/index.js b/server/index.js index 64b4138..65ae6bb 100755 --- a/server/index.js +++ b/server/index.js @@ -144,12 +144,26 @@ function notImplemented(req, res) })); } +function optionsHeader(req, res) +{ + res.setHeader('Access-Control-Allow-Origin', '*'); + res.setHeader('Access-Control-Request-Method', '*'); + res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET'); + res.setHeader('Access-Control-Allow-Headers', '*'); + if ( req.method === 'OPTIONS' ) + { + res.writeHead(200); + res.end(); + } +} + function processMethod(req, res) { switch(req.method) { case 'GET': getRoutes(req, res); break; case 'POST': postRoutes(req, res); break; + case 'OPTIONS': optionsHeader(req, res); break; default: notImplemented(req, res); } } -- cgit v1.2.3