我使用 http://localhost:3000 来开发我的网站,但我总是从 Sentry 收到 CROS 错误,我错过了什么?
在Sentry的设置中:我已将项目的允许域设置为*,但它看起来不起作用......
从源“http://localhost:3000”获取“my-sentry-dsn”的访问已被 CORS 策略阻止:请求的资源上不存在“Access-Control-Allow-Origin”标头。如果不透明响应满足您的需求,请将请求模式设置为“no-cors”以在禁用 CORS 的情况下获取资源。
Vue3+Vite
yarn add @sentry/tracing @sentry/vue
Run Code Online (Sandbox Code Playgroud)
在 main.ts 中
import * as Sentry from "@sentry/vue"
import { Integrations } from "@sentry/tracing"
const app = createApp(App)
// Initialize Sentry
const dsnSentry = import.meta.env.VITE_SENTRY_DSN as string
if (!!dsnSentry) {
const env = import.meta.env.VITE_ENV
const isDebug = env !== "production"
Sentry.init({
app,
dsn: dsnSentry,
// integrations: [new Integrations.BrowserTracing()],
integrations: [
new Integrations.BrowserTracing({
routingInstrumentation: Sentry.vueRouterInstrumentation(router),
tracingOrigins: ["localhost:3000", /^\//],
}),
],
tracesSampleRate: 1.0, …Run Code Online (Sandbox Code Playgroud)