Skip to content

Commit

Permalink
fix: allow origin to be only the same - fix #223
Browse files Browse the repository at this point in the history
  • Loading branch information
pagoru committed Dec 14, 2024
1 parent c9db168 commit b7649b2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/server/src/modules/system/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ export const api = () => {

try {
const { url, method } = request;
if (method === RequestMethod.OPTIONS)
if (method === RequestMethod.OPTIONS) {
const headers = getCORSHeaders() as Headers;
headers.set("Access-Control-Allow-Origin", System.getConfig().url);
return new Response(null, {
headers: getCORSHeaders(),
status: 204,
});
}

const parsedUrl = new URL(url);

Expand Down Expand Up @@ -76,6 +79,10 @@ export const api = () => {
if (foundMethodRequest) {
const response = await foundMethodRequest.func(request, parsedUrl);
appendCORSHeaders(response.headers);
response.headers.set(
"Access-Control-Allow-Origin",
System.getConfig().url,
);
return response;
}
if (foundRequests.length)
Expand Down

0 comments on commit b7649b2

Please sign in to comment.