mirror of
https://github.com/graphql-hive/console
synced 2026-05-23 17:18:23 +00:00
Add CORS headers to CDN Worker (#5559)
This commit is contained in:
parent
8b04c7adef
commit
49100f2fe9
1 changed files with 26 additions and 15 deletions
|
|
@ -192,8 +192,13 @@ const handler: ExportedHandler<Env> = {
|
|||
},
|
||||
});
|
||||
|
||||
const { corsify, preflight } = itty.createCors();
|
||||
|
||||
const router = itty
|
||||
.Router()
|
||||
// Handles all OPTIONS and preflight requests.
|
||||
// https://github.com/kwhitley/itty.dev/blob/v4.x/src/routes/itty-router/cors/%2Bpage.md#preflight-middleware
|
||||
.all('*', preflight)
|
||||
.get(
|
||||
'/_health',
|
||||
() =>
|
||||
|
|
@ -205,23 +210,29 @@ const handler: ExportedHandler<Env> = {
|
|||
// Legacy CDN Handlers
|
||||
.get('*', handleRequest);
|
||||
|
||||
try {
|
||||
return await router.handle(request, sentry.captureException.bind(sentry)).then(response => {
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
return (
|
||||
router
|
||||
.handle(request, sentry.captureException.bind(sentry))
|
||||
.then(response => {
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
sentry.addBreadcrumb({
|
||||
message: 'No response from router',
|
||||
});
|
||||
sentry.addBreadcrumb({
|
||||
message: 'No response from router',
|
||||
});
|
||||
|
||||
return createResponse(analytics, 'Not found', { status: 404 }, 'unknown', request);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
sentry.captureException(error);
|
||||
return new UnexpectedError(analytics, request);
|
||||
}
|
||||
return createResponse(analytics, 'Not found', { status: 404 }, 'unknown', request);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
sentry.captureException(error);
|
||||
return new UnexpectedError(analytics, request);
|
||||
})
|
||||
// Adds the appropriate CORS headers to any Response.
|
||||
// https://github.com/kwhitley/itty.dev/blob/v4.x/src/routes/itty-router/cors/%2Bpage.md#corsify
|
||||
.then(corsify)
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue