vuejs3在Local主机中获得CORS错误

发布于 2025-01-20 12:44:36 字数 985 浏览 1 评论 0原文

我正在使用http:// localhost:3000来开发我的网站,但是我总是从哨兵那里遇到CROS错误,我缺少什么?

在Sentry的设置中: 域设置为 *,但是看起来不起作用。

我已经将项目的允许 CORS策略:在请求的资源上没有“访问控制”标头。如果不透明的响应满足您的需求,请将请求模式设置为“无核”,以通过禁用CORS来获取资源。

vue3 + vite

yarn add @sentry/tracing @sentry/vue

在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,
    debug: isDebug,
  })
}

app.mount("#app")

I'm using http://localhost:3000 to development my website, but I always get CROS error from Sentry, what am I missing?

in Sentry's Setting:
I've set the project's Allowed Domains to *, but it's looks like not work....

Access to fetch at 'my-sentry-dsn' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Vue3 + Vite

yarn add @sentry/tracing @sentry/vue

in 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,
    debug: isDebug,
  })
}

app.mount("#app")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╭ゆ眷念 2025-01-27 12:44:36

我通过在tracingorigins param中使用*解决了这个问题。

这样:

Sentry.init({
  dsn: "__DNS__",
  integrations: [new BrowserTracing({ tracingOrigins: ["*"] })],
  tracesSampleRate: 1.0,
});

另一个问题,可以是Ads Block扩展名,例如Adblock,Ublock。

I solved this problem by using * in the tracingOrigins param.

Like this:

Sentry.init({
  dsn: "__DNS__",
  integrations: [new BrowserTracing({ tracingOrigins: ["*"] })],
  tracesSampleRate: 1.0,
});

Another problem, can be ads block extension like adblock, ublock.

深居我梦 2025-01-27 12:44:36

对于任何降落在这里的人,我都通过禁用Ublock Origin来修复它...

For whoever lands here, I fixed it by disabling uBlock origin...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文