[英]Express.js - Connect with GraphQL external API
I have problem with connect to external API (GraphQL) on Express.js . 我在Express.js上连接到外部API(GraphQL)时遇到问题。 Can You give me a some good tutorials about this?
您能给我一些很好的教程吗?
And one more question. 还有一个问题。 I have this error:
我有这个错误:
Link to error message - img 链接到错误消息-img
It's possible to connect with this API ? 可以与此API连接吗?
Try adding the following middleware to your NodeJS/Express app (I have added some comments for your convenience): 尝试将以下中间件添加到您的NodeJS / Express应用程序(为方便起见,我添加了一些注释):
// Add headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8888');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.