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

fix cors issues (2 options) #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Sentry from "@sentry/browser";
*
* Access to fetch at 'http://localhost:3000/real-download-path' (redirected from 'http://localhost:5173/api/download') from origin 'http://localhost:5173' has been blocked by CORS policy: Request header field baggage is not allowed by Access-Control-Allow-Headers in preflight response.
*/
const WITH_SENTRY = false;
const WITH_SENTRY = true;

if (WITH_SENTRY) {
Sentry.init({
Expand All @@ -18,6 +18,8 @@ if (WITH_SENTRY) {
// We recommend adjusting this value in production, or using tracesSampler
// for finer control
tracesSampleRate: 1.0,
// Option 2: Disable distributed tracing. You can also make this more fine-grained and only include some domains via regex or string.include matching.
// tracePropagationTargets: []
});
}

Expand Down
3 changes: 2 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ app.use((req, res, next) => {
res.header("Access-Control-Allow-Credentials", "true");
res.header("Access-Control-Allow-Methods", "GET,HEAD,PUT,PATCH,POST,DELETE");
res.header("Access-Control-Expose-Headers", "Content-Length");
// Option 1: Allow `sentry-trace` and `baggage` headers in your CORS response headers:
res.header(
"Access-Control-Allow-Headers",
"Accept, Authorization, Content-Type, X-Requested-With, Range"
"Accept, Authorization, Content-Type, X-Requested-With, Range, baggage, sentry-trace"
);

if (req.method === "OPTIONS") {
Expand Down