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 <tukon479@gmail.com>
This commit is contained in:
Innei
2025-05-05 16:18:23 +08:00
parent d2e945fbe4
commit af67ca184f
2 changed files with 2 additions and 6 deletions

View File

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

View File

@@ -138,12 +138,6 @@ export async function CreateAuth(
const handler = async (req: IncomingMessage, res: ServerResponse) => {
try {
res.setHeader('access-control-allow-methods', 'GET, POST')
res.setHeader('access-control-allow-headers', 'content-type')
res.setHeader(
'Access-Control-Allow-Origin',
req.headers.origin || req.headers.referer || req.headers.host || '*',
)
res.setHeader('access-control-allow-credentials', 'true')
const clonedRequest = new IncomingMessage(req.socket)