Hapi: reenable cors test

It seems that hapi does not send all allowed origins in the
Access-Control-Allow-Origin header, so it is necessary to use another
configuration option to see if the config is being propagated
This commit is contained in:
Evans Hauser 2018-06-25 16:05:59 -07:00
parent 209764324f
commit c88630333c
No known key found for this signature in database
GPG key ID: 88AF586817F52EEC
2 changed files with 20 additions and 8 deletions

View file

@ -183,18 +183,27 @@ describe('apollo-server-hapi', () => {
});
});
// XXX currently this test fails. Unsure why, since the otpins are passed
// correctly to the server.route call in graphqlHapi
xit('accepts cors configuration', async () => {
it('accepts cors configuration', async () => {
server = new ApolloServer({
typeDefs,
resolvers,
});
app = new Server({ port: 4000 });
app = new Server({
port: 4000,
});
await server.applyMiddleware({
app,
cors: { origin: ['apollographql.com'] },
cors: {
additionalExposedHeaders: ['X-Apollo'],
exposedHeaders: [
'Accept',
'Authorization',
'Content-Type',
'If-None-Match',
'Another-One',
],
},
});
await app.start();
@ -203,9 +212,12 @@ describe('apollo-server-hapi', () => {
const apolloFetch = createApolloFetch({ uri }).useAfter(
(response, next) => {
console.log(response.response.headers);
expect(
response.response.headers.get('access-control-allow-origin'),
).to.equal('apollographql.com');
response.response.headers.get('access-control-expose-headers'),
).to.deep.equal(
'Accept,Authorization,Content-Type,If-None-Match,Another-One,X-Apollo',
);
next();
},
);

View file

@ -126,7 +126,7 @@ export class ApolloServer extends ApolloServerBase {
await app.register({
plugin: graphqlHapi,
options: {
path: path,
path,
graphqlOptions: this.createGraphQLServerOptions.bind(this),
route: {
cors: cors !== undefined ? cors : true,