The host entered by the user cannot be obtained in the context of ApolloServer
It is possible in WebApp.connectHandlers.use. How can I get the same value in the context of ApolloServer?
This is my code, Get the host in the Context of ApolloServer and get the result: localhost:4000
const server = new ApolloServer({
schema,
context: async ctx => {
console.log('Apollo server context: ', ctx.req.headers.host);
//Apollo server context: localhost:4000
},
});
server.applyMiddleware({
app: WebApp.connectHandlers,
path: '/graphql',
});
WebApp.connectHandlers.use('/graphql', (req, res) => {
if (req.method === 'GET') {
res.end();
}
});
The host result obtained in WebApp.connectHandlers.use is the entered hostname, such as hello.com
WebApp.connectHandlers.use((req, res, next) => {
if (req.headers && req.headers.host) {
console.log('WebApp connectHandlers: ', req.headers.host);
//WebApp connectHandlers: hello.com
}
return next();
});
What do I have to do to get hello.com in the context of ApolloServer? Please help me, thank you