-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcors.js
More file actions
41 lines (37 loc) ยท 767 Bytes
/
cors.js
File metadata and controls
41 lines (37 loc) ยท 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* CORS ํค๋ ๋ฐ ์๋ต ์ ํธ๋ฆฌํฐ
*/
/**
* CORS ํค๋
*/
export const CORS_HEADERS = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
};
/**
* CORS๋ฅผ ํฌํจํ JSON ์๋ต ์์ฑ
*/
export function corsResponse(data, status = 200) {
return new Response(JSON.stringify(data), {
status,
headers: {
...CORS_HEADERS,
"Content-Type": "application/json",
},
});
}
/**
* CORS preflight ์๋ต
*/
export function preflightResponse() {
return new Response(null, {
headers: CORS_HEADERS,
});
}
/**
* ์๋ฌ ์๋ต
*/
export function errorResponse(message, status = 500) {
return corsResponse({ error: message }, status);
}