Skip to content

Commit

Permalink
apollo-server: Support onHealthCheck in ApolloServer constructor. (
Browse files Browse the repository at this point in the history
…#2672)

Support `onHealthCheck` in the `ApolloServer` constructor for `apollo-server` (the "quick start" package) in the same way as `cors` is supported.  This contrasts with the `-express`, `-hapi`, etc. variations which accept this parameter via their `applyMiddleware` methods and will remain as-is.
  • Loading branch information
garrypolley authored and abernix committed May 23, 2019
1 parent accf3eb commit f4c958a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# vNEXT

- `apollo-server`: Support `onHealthCheck` in the `ApolloServer` constructor in the same way as `cors` is supported. This contrasts with the `-express`, `-hapi`, etc. variations which accept this parameter via their `applyMiddleware` methods and will remain as-is. [PR #2672](https://github.com/apollographql/apollo-server/pull/2672)
- core: Expose SHA-256 hex hash digest of the Engine API key to plugins, when available, as `engine.apiKeyHash`. [PR# 2685](https://github.com/apollographql/apollo-server/pull/2685)
- `apollo-datasource-rest`: If another `Content-type` is already set on the response, don't overwrite it with `application/json`, allowing the user's initial `Content-type` to prevail. [PR #2520](https://github.com/apollographql/apollo-server/issues/2035)

Expand Down
4 changes: 4 additions & 0 deletions packages/apollo-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ export interface ServerInfo {
export class ApolloServer extends ApolloServerBase {
private httpServer?: http.Server;
private cors?: CorsOptions | boolean;
private onHealthCheck?: (req: express.Request) => Promise<any>;

constructor(
config: ApolloServerExpressConfig & {
cors?: CorsOptions | boolean;
onHealthCheck?: (req: express.Request) => Promise<any>;
},
) {
super(config);
this.cors = config && config.cors;
this.onHealthCheck = config && config.onHealthCheck;
}

private createServerInfo(
Expand Down Expand Up @@ -90,6 +93,7 @@ export class ApolloServer extends ApolloServerBase {
app,
path: '/',
bodyParserConfig: { limit: '50mb' },
onHealthCheck: this.onHealthCheck,
cors:
typeof this.cors !== 'undefined'
? this.cors
Expand Down

0 comments on commit f4c958a

Please sign in to comment.