mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 02:01:40 -05:00
apollo-server-hapi: fix graphql gui request, bind server listen, and check for autoListen: false
This commit is contained in:
parent
98ca26a303
commit
6b80ac96a1
1 changed files with 22 additions and 4 deletions
|
@ -35,9 +35,10 @@ export const registerServer = async ({
|
|||
if (request.path !== path) {
|
||||
return h.continue;
|
||||
}
|
||||
|
||||
if (!server.disableTools && request.method === 'get') {
|
||||
//perform more expensive content-type check only if necessary
|
||||
const accept = parseAll(request.app);
|
||||
const accept = parseAll(request.headers);
|
||||
const types = accept.mediaTypes as string[];
|
||||
const prefersHTML =
|
||||
types.find(
|
||||
|
@ -50,10 +51,11 @@ export const registerServer = async ({
|
|||
renderPlaygroundPage({
|
||||
subscriptionsEndpoint: server.subscriptions && path,
|
||||
endpoint: path,
|
||||
version: '',
|
||||
version: '1.4.0',
|
||||
}),
|
||||
)
|
||||
.type('text/html');
|
||||
.type('text/html')
|
||||
.takeover();
|
||||
}
|
||||
}
|
||||
return h.continue;
|
||||
|
@ -73,12 +75,28 @@ export const registerServer = async ({
|
|||
|
||||
server.use({ path, getHttp: () => app.listener });
|
||||
|
||||
const listen = server.listen;
|
||||
const listen = server.listen.bind(server);
|
||||
server.listen = async options => {
|
||||
//requires that autoListen is false, so that
|
||||
//hapi sets up app.listener without start
|
||||
await app.start();
|
||||
|
||||
//While this is not strictly necessary, it ensures that apollo server calls
|
||||
//listen first, setting the port. Otherwise the hapi server constructor
|
||||
//sets the port
|
||||
if (app.listener.listening) {
|
||||
throw Error(
|
||||
`
|
||||
Ensure that constructor of Hapi server sets autoListen to false, as follows:
|
||||
|
||||
const app = Hapi.server({
|
||||
autoListen: false,
|
||||
//other parameters
|
||||
});
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
//starts the hapi listener at a random port when engine proxy used,
|
||||
//otherwise will start the server at the provided port
|
||||
return listen({ ...options });
|
||||
|
|
Loading…
Add table
Reference in a new issue