【问题标题】:CORS Apollo React only FrontendCORS Apollo 仅 React 前端
【发布时间】:2018-01-26 07:36:57
【问题描述】:

我有一个非常愚蠢的问题。我有一个不是我的在线服务器的 graphQL API。我对 CORS 有一些问题(当我在浏览器中做一些魔术时工作正常)。像这样的每个问题都是关于服务器端的,但在这里我不能对服务器做任何事情。那么有没有可能通过前端获取数据而没有任何问题?我使用 React Apollo 堆栈。

【问题讨论】:

标签: cors apollo react-apollo


【解决方案1】:

我修复了 cors 问题,将这一行“graphQLServer.use(cors())”添加到我的 graphql 服务器:

import cors from 'cors';

const graphQLServer = express();
graphQLServer.use(cors()); // with this line the cors problem is solved
...
graphQLServer.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
graphQLServer.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));

【讨论】:

    猜你喜欢
    • 2016-07-21
    • 2021-04-26
    • 2021-10-24
    • 1970-01-01
    • 2022-06-30
    • 2020-03-01
    • 1970-01-01
    • 2020-12-14
    • 2019-08-07
    相关资源
    最近更新 更多