Skip to content

Commit

Permalink
misc: Allow CORS in vercel.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyphyn committed Jul 4, 2023
1 parent 16ff305 commit 3bc9c67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export async function handle({ event, resolve }) {
// annoying hack to fix lemmy's CORS
if (event.url.pathname.startsWith('/cors')) {
// cut off the 1st slash (empty), and remove the /cors

event.request.headers.delete('origin')
event.request.headers.delete('host')

Expand Down Expand Up @@ -58,7 +57,6 @@ export async function handle({ event, resolve }) {
)
}
} catch (error) {
console.error(error)
return new Response(
JSON.stringify({
message: 'the proxy failed to fetch from server',
Expand Down
22 changes: 22 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"headers": [
{
"source": "/cors/(.*)",
"headers": [
{ "key": "Access-Control-Allow-Credentials", "value": "true" },

{ "key": "Access-Control-Allow-Origin", "value": "*" },

{
"key": "Access-Control-Allow-Methods",
"value": "GET,OPTIONS,PATCH,DELETE,POST,PUT"
},

{
"key": "Access-Control-Allow-Headers",
"value": "X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version"
}
]
}
]
}

0 comments on commit 3bc9c67

Please sign in to comment.