This repository was archived by the owner on Jul 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,26 @@ using HTTP
3
3
using Dates
4
4
using JSON
5
5
6
+ const CORS_HEADERS = [
7
+ " Access-Control-Allow-Origin" => " *" ,
8
+ " Access-Control-Allow-Headers" => " *" ,
9
+ " Access-Control-Allow-Methods" => " POST, GET, OPTIONS"
10
+ ]
11
+
12
+ # https://juliaweb.github.io/HTTP.jl/stable/examples/#Cors-Server
13
+ function CorsMiddleware (handler)
14
+ return function (req:: HTTP.Request )
15
+ @debug " CORS middleware"
16
+ # determine if this is a pre-flight request from the browser
17
+ if HTTP. method (req)== " OPTIONS"
18
+ return HTTP. Response (200 , CORS_HEADERS)
19
+ else
20
+ return handler (req) # passes the request to the AuthMiddleware
21
+ end
22
+ end
23
+ end
24
+
25
+
6
26
function setup_jwt_middleware (config:: Dict )
7
27
if ! get (config[" jwt_auth" ], " JWT_ENABLED" , false )
8
28
return identity # Return a pass-through middleware if JWT is not enabled
Original file line number Diff line number Diff line change @@ -168,9 +168,9 @@ function start_server(config_path)
168
168
println (" Initialisation complete, starting server on port 8000." )
169
169
println (" Starting with $(Threads. nthreads ()) threads..." )
170
170
if Threads. nthreads () > 1
171
- serveparallel (host= " 0.0.0.0" , port= 8000 )
171
+ serveparallel (middleware = [CorsMiddleware], host= " 0.0.0.0" , port= 8000 )
172
172
else
173
- serve (host= " 0.0.0.0" , port= 8000 )
173
+ serve (middleware = [CorsMiddleware], host= " 0.0.0.0" , port= 8000 )
174
174
end
175
175
end
176
176
You can’t perform that action at this time.
0 commit comments