Skip to content

Commit

Permalink
fix: cors request
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed May 17, 2024
1 parent ea9b1ee commit ba8282c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
12 changes: 9 additions & 3 deletions backend/funix/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
app.secret_key = GlobalSwitchOption.get_session_key()
app.config.update(
SESSION_COOKIE_PATH="/",
SESSION_COOKIE_SAMESITE="Lax",
SESSION_COOKIE_SAMESITE="None",
SESSION_TYPE="filesystem",
)
sock = Sock(app)

Expand Down Expand Up @@ -69,11 +70,16 @@ def privacy_policy(message: str) -> None:

@app.after_request
def funix_auto_cors(response: Response) -> Response:
response.headers["Access-Control-Allow-Origin"] = "*"
if "HTTP_ORIGIN" not in request.environ:
response.headers["Access-Control-Allow-Origin"] = "*"
else:
response.headers["Access-Control-Allow-Credentials"] = "true"
response.headers["Access-Control-Allow-Origin"] = request.environ["HTTP_ORIGIN"]
response.headers[
"Access-Control-Allow-Methods"
] = "GET, HEAD, POST, OPTIONS, PUT, PATCH, DELETE"
response.headers["Access-Control-Allow-Headers"] = "*"
response.headers["Access-Control-Allow-Headers"] = "Content-Type, *"

return response


Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/FunixFunction/InputPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const InputPanel = (props: {
"Content-Type": "application/json",
},
body: JSON.stringify(formData),
credentials: "include",
})
.then((body) => {
return body.json();
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/FunixFunction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ const FunixFunction: React.FC<FunctionDetailProps> = ({ preview, backend }) => {
return;
}
queryLock.current = true;
fetch(new URL(`/param/${preview.id}`, backend).toString())
fetch(new URL(`/param/${preview.id}`, backend).toString(), {
credentials: "include",
})
.then((body) => {
return body.json();
})
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export async function getList(
return f(url, {
...init,
method: "GET",
credentials: "include",
});
}

Expand Down Expand Up @@ -164,6 +165,7 @@ export async function getParam(
return f(url, {
...init,
method: "GET",
credentials: "include",
});
}

Expand Down Expand Up @@ -196,6 +198,7 @@ export async function callFunction(
...init?.headers,
"Content-Type": "application/json",
},
credentials: "include",
});
}

Expand All @@ -212,6 +215,7 @@ export async function callFunctionRaw(
...init?.headers,
"Content-Type": "application/json",
},
credentials: "include",
}).then((response) => response.text());
}

Expand All @@ -228,6 +232,7 @@ export async function verifyToken(
...init?.headers,
"Content-Type": "application/json",
},
credentials: "include",
}).then((response) => response.success);
}

Expand Down

0 comments on commit ba8282c

Please sign in to comment.