Skip to content

Commit 7eed043

Browse files
committed
src: utils[cors]
1 parent 8d912df commit 7eed043

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/utils/cors.cr

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,25 @@
1616
# Copyright (C) 2025 Krisna Pranav, MoonScript Developers
1717

1818
module MoonScript
19-
class CORS
20-
include HTTP::Handler
19+
class CORS
20+
include HTTP::Handler
21+
22+
def call(context)
23+
## Response headers which supports the web type.
24+
context.response.headers["Access-Control-Max-Age"] = 1.day.total_seconds.to_i.to_s
25+
context.response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, PATCH"
26+
context.response.headers["Access-Control-Allow-Headers"] = "Content-Type"
27+
context.response.headers["Access-Control-Allow-Credentials"] = "true"
28+
context.response.headers["Access-Control-Allow-Origin"] = "*"
29+
30+
## Case checking
31+
if context.request.method.upcase == "OPTIONS"
32+
context.response.content_type = "text/html; charset=utf-8"
33+
context.response.status = :ok
34+
else
35+
call_next context
36+
end
2137

22-
def call(context)
23-
context.response.headers["Accept-Control-Max-Age"] = 1.day.total_seconds.to_i.to_s
24-
context.response.headers["Acccess-Control-Allow-Method"] = "GET, POSt, PUT, PATCH"
25-
end
2638
end
27-
end
39+
end
40+
end

0 commit comments

Comments
 (0)