Skip to content

Commit

Permalink
fix: nitro server cors support with cookie
Browse files Browse the repository at this point in the history
* 修复nitro server在使用cookie时的跨域配置
  • Loading branch information
mynetfan committed Feb 17, 2025
1 parent b6b97ac commit 947ab91
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions apps/backend-mock/middleware/1.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export default defineEventHandler((event) => {
event.node.res.setHeader(
'Access-Control-Allow-Origin',
event.headers.get('Origin') ?? '*',
);
if (event.method === 'OPTIONS') {
event.node.res.statusCode = 204;
event.node.res.statusMessage = 'No Content.';
Expand Down
3 changes: 2 additions & 1 deletion apps/backend-mock/nitro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export default defineNitroConfig({
cors: true,
headers: {
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Headers':
'Accept, Authorization, Content-Length, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With',
'Access-Control-Allow-Methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
'Access-Control-Allow-Origin': '*',
'Access-Control-Expose-Headers': '*',
Expand Down

0 comments on commit 947ab91

Please # to comment.