Skip to content

Commit d4b15bb

Browse files
authored
feat: Added support for HTTPS server option
Closes #210
2 parents 6e998a5 + c9252cf commit d4b15bb

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ The `options` object has the following fields:
119119
| `subscriptions` | Object or String or `false` | `'/'` | Defines the subscriptions (websocket) endpoint for your server; accepts an object with [subscription server options](https://github.com/apollographql/subscriptions-transport-ws#constructoroptions-socketoptions) `path`, `keepAlive`, `onConnect` and `onDisconnect`; setting to `false` disables subscriptions completely |
120120
| `playground` | String or `false` | `'/'` | Defines the endpoint where you can invoke the [Playground](https://github.com/graphcool/graphql-playground); setting to `false` disables the playground endpoint |
121121
| `uploads` | [UploadOptions](/src/types.ts#L39-L43) or `false` or `undefined` | `null` | Provides information about upload limits; the object can have any combination of the following three keys: `maxFieldSize`, `maxFileSize`, `maxFiles`; each of these have values of type Number; setting to `false` disables file uploading |
122+
| `https` | [HttpsOptions](/src/types.ts#L62-L65) or `undefined` | `undefined` | Enables HTTPS support with a key/cert |
122123

123124
Additionally, the `options` object exposes these `apollo-server` options:
124125

src/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { importSchema } from 'graphql-import'
1414
import expressPlayground from 'graphql-playground-middleware-express'
1515
import { makeExecutableSchema } from 'graphql-tools'
1616
import { createServer, Server } from 'http'
17+
import { createServer as createHttpsServer, Server as HttpsServer} from 'https';
1718
import * as path from 'path'
1819
import { SubscriptionServer } from 'subscriptions-transport-ws'
1920

@@ -96,12 +97,12 @@ export class GraphQLServer {
9697
start(
9798
options: Options,
9899
callback?: ((options: Options) => void),
99-
): Promise<Server>
100-
start(callback?: ((options: Options) => void)): Promise<Server>
100+
): Promise<Server|HttpsServer>
101+
start(callback?: ((options: Options) => void)): Promise<Server|HttpsServer>
101102
start(
102103
optionsOrCallback?: Options | ((options: Options) => void),
103104
callback?: ((options: Options) => void),
104-
): Promise<Server> {
105+
): Promise<Server|HttpsServer> {
105106
const options =
106107
optionsOrCallback && typeof optionsOrCallback === 'function'
107108
? {}
@@ -223,16 +224,16 @@ export class GraphQLServer {
223224
}
224225

225226
return new Promise((resolve, reject) => {
226-
if (!subscriptionServerOptions) {
227-
const server = createServer(app)
227+
const server: Server|HttpsServer = this.options.https ?
228+
createHttpsServer(this.options.https, app) : createServer(app);
228229

230+
if (!subscriptionServerOptions) {
229231
server.listen(this.options.port, () => {
230232
callbackFunc(this.options)
231233
resolve(server)
232234
})
233235
} else {
234-
const combinedServer = createServer(app)
235-
236+
const combinedServer = server;
236237
combinedServer.listen(this.options.port, () => {
237238
callbackFunc(this.options)
238239
resolve(combinedServer)

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,19 @@ export interface ApolloServerOptions {
5959
debug?: boolean
6060
}
6161

62+
export interface HttpsOptions {
63+
cert: string
64+
key: string
65+
}
66+
6267
export interface Options extends ApolloServerOptions {
6368
port?: number
6469
cors?: CorsOptions | false
6570
uploads?: UploadOptions | false
6671
endpoint?: string
6772
subscriptions?: SubscriptionServerOptions | string | false
6873
playground?: string | false
74+
https?: HttpsOptions
6975
}
7076

7177
export interface SubscriptionServerOptions {

0 commit comments

Comments
 (0)