Skip to content

Commit

Permalink
Allow additional Hapi route options to be passed (#1384)
Browse files Browse the repository at this point in the history
* Allow additional route options to be passed

* Updated changelog with PR
  • Loading branch information
robinvdvleuten authored and evans committed Aug 14, 2018
1 parent 5b8acaa commit 989481f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All of the packages in the `apollo-server` repo are released with the same versi

### vNEXT

- Hapi: Allow additional route options to be passed to Hapi.js plugin. [PR #1384](https://github.com/apollographql/apollo-server/pull/1384)
- express, koa: remove next after playground [#1436](https://github.com/apollographql/apollo-server/pull/1436)
- Hapi: Pass the response toolkit to the context function. [#1407](https://github.com/apollographql/apollo-server/pull/1407)
- update apollo-engine-reporting-protobuf to non-beta [#1429](https://github.com/apollographql/apollo-server/pull/1429)
Expand Down
11 changes: 8 additions & 3 deletions packages/apollo-server-hapi/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class ApolloServer extends ApolloServerBase {
app,
cors,
path,
route,
disableHealthCheck,
onHealthCheck,
}: ServerRegistration) {
Expand Down Expand Up @@ -122,9 +123,12 @@ export class ApolloServer extends ApolloServerBase {
options: {
path,
graphqlOptions: this.createGraphQLServerOptions.bind(this),
route: {
cors: cors !== undefined ? cors : true,
},
route:
route !== undefined
? route
: {
cors: cors !== undefined ? cors : true,
},
},
});

Expand All @@ -136,6 +140,7 @@ export interface ServerRegistration {
app?: hapi.Server;
path?: string;
cors?: boolean | hapi.RouteOptionsCors;
route?: hapi.RouteOptions;
onHealthCheck?: (request: hapi.Request) => Promise<any>;
disableHealthCheck?: boolean;
uploads?: boolean | Record<string, any>;
Expand Down
44 changes: 44 additions & 0 deletions packages/apollo-server-hapi/src/__tests__/ApolloServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,50 @@ describe('apollo-server-hapi', () => {
await apolloFetch({ query: '{hello}' });
});

it('accepts custom route configuration', async () => {
server = new ApolloServer({
typeDefs,
resolvers,
});
app = new Server({
port,
});

await server.applyMiddleware({
app,
route: {
cors: {
additionalExposedHeaders: ['X-Apollo'],
exposedHeaders: [
'Accept',
'Authorization',
'Content-Type',
'If-None-Match',
'Another-One',
],
},
},
});

await app.start();

httpServer = app.listener;
const uri = app.info.uri + '/graphql';

const apolloFetch = createApolloFetch({ uri }).useAfter(
(response, next) => {
expect(
response.response.headers.get('access-control-expose-headers'),
).toEqual(
'Accept,Authorization,Content-Type,If-None-Match,Another-One,X-Apollo',
);
next();
},
);

await apolloFetch({ query: '{hello}' });
});

it('passes each request and response toolkit through to the context function', async () => {
const context = async ({ request, h }) => {
expect(request).toBeDefined();
Expand Down

0 comments on commit 989481f

Please sign in to comment.