-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (25 loc) · 901 Bytes
/
server.js
File metadata and controls
30 lines (25 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as http from 'http'
import stoppable from 'stoppable'
import util from 'util'
import { logger } from './logger'
/**
* Creates and returns a new Koa application.
* Does *NOT* call `listen`!
*
* @return {Promise<http.Server>} The configured app.
*/
export async function createServer(callback) {
logger.debug('Creating server...')
// Creates a http server ready to listen.
const server = stoppable(http.createServer(callback))
server.stop = util.promisify(server.stop)
// Add a `close` event listener so we can clean up resources.
server.on('close', () => {
// You should tear down database connections, TCP connections, etc
// here to make sure Jest's watch-mode some process management
// tool does not release resources.
logger.debug('Server closing, bye!')
})
logger.debug('Server created, ready to listen', { scope: 'startup' })
return server
}