Skip to content

Commit af67ca1

Browse files
committed
chore: enhance CORS configuration in bootstrap and auth implementation
- Added comprehensive CORS methods support in `bootstrap.ts` to allow various HTTP methods. - Removed redundant CORS headers from the `CreateAuth` function in `auth.implement.ts` to streamline the response handling. Signed-off-by: Innei <[email protected]>
1 parent d2e945f commit af67ca1

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

apps/core/src/bootstrap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export async function bootstrap() {
4242

4343
const allowAllCors: FastifyCorsOptions = {
4444
credentials: true,
45+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
4546
origin: (origin, callback) => callback(null, origin || ''),
4647
}
4748
// Origin 如果不是数组就全部允许跨域
@@ -69,6 +70,7 @@ export async function bootstrap() {
6970
credentials: true,
7071
preflightContinue: false,
7172
optionsSuccessStatus: 204,
73+
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
7274
}
7375
: allowAllCors,
7476
)

apps/core/src/modules/auth/auth.implement.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ export async function CreateAuth(
138138

139139
const handler = async (req: IncomingMessage, res: ServerResponse) => {
140140
try {
141-
res.setHeader('access-control-allow-methods', 'GET, POST')
142-
res.setHeader('access-control-allow-headers', 'content-type')
143-
res.setHeader(
144-
'Access-Control-Allow-Origin',
145-
req.headers.origin || req.headers.referer || req.headers.host || '*',
146-
)
147141
res.setHeader('access-control-allow-credentials', 'true')
148142

149143
const clonedRequest = new IncomingMessage(req.socket)

0 commit comments

Comments
 (0)