Configure the local /etc/hosts file to make the domain name point to 127.0.0.1
127.0.0.1 hello.com
Then start the ApolloServer application, the middleware uses express
The req.headers.host of ApolloServer gets the host of the server, which is localhost:4000, and what I input in the browser is hello.com:4000,
import { ApolloServer, makeExecutableSchema } from 'apollo-server-express';
import { WebApp } from 'meteor/webapp';
import typeDefs from './type';
import resolvers from './resolver';
const schema = makeExecutableSchema({
typeDefs,
resolvers,
resolverValidationOptions: { requireResolversForResolveType: false },
});
const server = new ApolloServer({
schema,
context: async ctx => {
console.log(ctx.req.headers);
return ctx;
},
});
server.applyMiddleware({
app: WebApp.connectHandlers,
path: '/graphql'
});
I20210203-13:20:31.667(8)? {
I20210203-13:20:31.667(8)? 'x-forwarded-host': 'localhost:4000',
I20210203-13:20:31.668(8)? 'x-forwarded-proto': 'http',
I20210203-13:20:31.668(8)? 'x-forwarded-port': '4000',
I20210203-13:20:31.668(8)? 'x-forwarded-for': '127.0.0.1',
I20210203-13:20:31.668(8)? host: 'localhost:4000',
I20210203-13:20:31.668(8)? connection: 'close',
I20210203-13:20:31.668(8)? 'accept-encoding': 'gzip,deflate',
I20210203-13:20:31.668(8)? 'user-agent': 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)',
I20210203-13:20:31.669(8)? 'content-length': '256',
I20210203-13:20:31.669(8)? clientsidehostname: 'http://localhost:4000/',
I20210203-13:20:31.669(8)? 'content-type': 'application/json',
I20210203-13:20:31.669(8)? accept: '*/*'
I20210203-13:20:31.669(8)? }
I20210203-13:20:31.744(8)? f
Only the server’s headers are obtained
How to obtain the client’s headers parameter?
So how can I get hello.com:4000,
or give me a hint, which direction should I look for?
Any suggestions, please help