【发布时间】:2021-03-05 13:11:52
【问题描述】:
我正在关注 Ryan Chenkie 的(优秀)安全教程,但尝试使用 graphql api 而不是他使用的 REST api。
graphql 服务器在 localhost:4000 上运行,Apollo-React 客户端在 localhost:3000 上运行。它工作正常。
现在,我想为身份验证令牌使用 cookie,因此我需要客户端和服务器位于同一个域中。 根据 Chenkie 的建议,我在 package.json 中的客户端上设置了代理
"proxy": "http://localhost:4000/"
然后在我设置了 apollo 客户端的 index.js 中,我创建一个 httplink,如下所示:
const link = createHttpLink({
uri: "http://localhost:3000",
headers: { authorization: token }, // The token in the auth header will be removed when the cookie approach is working)
});
对于 uri,我尝试了以下方法:
uri: "http://localhost:3000"
uri: "/graphql"
uri: "/"
uri: ""
我总是收到 404 错误。 知道我做错了什么吗?
感谢您的帮助。
【问题讨论】:
标签: react-apollo apollo-client apollo-server