Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Add CORS headers to CDN Worker" #5561

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 15 additions & 26 deletions packages/services/cdn-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,8 @@ 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',
() =>
Expand All @@ -210,29 +205,23 @@ const handler: ExportedHandler<Env> = {
// Legacy CDN Handlers
.get('*', handleRequest);

return (
router
.handle(request, sentry.captureException.bind(sentry))
.then(response => {
if (response) {
return response;
}
try {
return await 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);
})
// 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)
);
return createResponse(analytics, 'Not found', { status: 404 }, 'unknown', request);
});
} catch (error) {
console.error(error);
sentry.captureException(error);
return new UnexpectedError(analytics, request);
}
},
};

Expand Down
Loading