设置标头后,为什么我仍然会在Apollo Studio中遇到CORS问题?

发布于 2025-01-26 05:49:34 字数 1765 浏览 6 评论 0原文

我正在从事使用OIDC的服务。会话ID存储在一个名为Pat的曲奇中。我可以使用Postman与GraphQL服务进行交互,因此我知道服务本身正在工作。但是,当我尝试与工作室访问时,它会失败。这是服务器...

import {ApolloServer} from "apollo-server";
import config from "./graphql/index.mjs"



class EddieBrockApp {
  constructor(schema, plugin){
    this.server = new ApolloServer({
      config,
      schema,
      plugins: [plugin],
      cors: {
        origin: ["https://mysite.co", "https://studio.apollographql.com"],
        credentials: true,
      },
    });
  }
  start(){
    this.server.listen({port: 4200})
      .then(this.onStart)
  }
  onStart({url}){
    console.log("Started at ", url);
  }
}
export default EddieBrockApp

Studio显示2个调用一个呼叫cors失败消息的选项,一个发表ns_error_dom_bad_uri

我尝试添加一个函数以显式设置标题...

context: ({res}) => {
    res.header('test-header', 'my-header');
    res.header('Vary', 'Origin');
    res.header('Access-Control-Allow-Origin', 'https://studio.apollographql.com');
}

我看到了标题...

​我尝试他们的调试,然后得到...

npx [email protected] --endpoint=https://mysite.co

但是我得到了...

⚠️  OPTIONS response returned 404. Is the url correct? Are authorization headers or cookies required?
⚠️  OPTIONS response is missing header 'access-control-allow-methods: POST'
⚠️  POST response returned 404. Is the url correct? Are authorization headers or cookies required?
⚠️  POST response missing 'access-control-allow-origin' header.

我在做什么错,我如何避免这些CORS问题?

I am working on a service that uses OIDC. The session ID is stored in a cookie called PAT. I can interact with the graphql service using Postman so I know the service itself is working. However, when I try to access with the studio it fails. Here is the server...

import {ApolloServer} from "apollo-server";
import config from "./graphql/index.mjs"



class EddieBrockApp {
  constructor(schema, plugin){
    this.server = new ApolloServer({
      config,
      schema,
      plugins: [plugin],
      cors: {
        origin: ["https://mysite.co", "https://studio.apollographql.com"],
        credentials: true,
      },
    });
  }
  start(){
    this.server.listen({port: 4200})
      .then(this.onStart)
  }
  onStart({url}){
    console.log("Started at ", url);
  }
}
export default EddieBrockApp

The studio shows 2 calls one to Options with a CORS failed message and one to POST that says NS_ERROR_DOM_BAD_URI

I tried to add a function to explicitly set the headers...

context: ({res}) => {
    res.header('test-header', 'my-header');
    res.header('Vary', 'Origin');
    res.header('Access-Control-Allow-Origin', 'https://studio.apollographql.com');
}

I see the headers...

enter image description here

But still the Apollo studio fails. I try their debug and I get...

npx [email protected] --endpoint=https://mysite.co

But I get...

⚠️  OPTIONS response returned 404. Is the url correct? Are authorization headers or cookies required?
⚠️  OPTIONS response is missing header 'access-control-allow-methods: POST'
⚠️  POST response returned 404. Is the url correct? Are authorization headers or cookies required?
⚠️  POST response missing 'access-control-allow-origin' header.

What am I doing wrong how do I avoid these CORS issues?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文