Skip to content

Commit

Permalink
fixed CORS bug
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Dec 16, 2022
1 parent c5cae05 commit e4f200c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions sharegpt-app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,38 @@ const nextConfig = {
},
],
},
{
source: "/api/save",
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",
},
],
},
{
source: "/api/conversations",
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",
},
],
},
];
},
async rewrites() {
Expand Down
4 changes: 4 additions & 0 deletions sharegpt-app/pages/api/conversations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export default async function handler(
});
res.status(200).json(response);

// OPTIONS /api/conversations (for CORS)
} else if (req.method === "OPTIONS") {
res.status(200).send("OK");

// POST /api/conversations (for saving conversations)
} else if (req.method === "POST") {
const { success } = await ratelimit.limit("sharegpt-save-endpoint");
Expand Down

1 comment on commit e4f200c

@vercel
Copy link

@vercel vercel bot commented on e4f200c Dec 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.