Browse Source
fix: nitro server cors support with cookie (#5549)
* 修复nitro server在使用cookie时的跨域配置
pull/5550/head
Netfan
12 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
6 additions and
1 deletions
-
apps/backend-mock/middleware/1.api.ts
-
apps/backend-mock/nitro.config.ts
|
|
|
@ -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.'; |
|
|
|
|
|
|
|
@ -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': '*', |
|
|
|
|