-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (25 loc) · 910 Bytes
/
index.js
File metadata and controls
29 lines (25 loc) · 910 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
const http = require('http')
const httpServer = http.Server
const httpsServer = require('https').Server
module.exports = (config = {}) => {
const router = config.router || require('./lib/router/sequential')(config)
const server = config.server || http.createServer()
// Default to true even when a partial config is provided. Keeping the default
// in the parameter alone would silently flip it off for any `zero({ ... })` call.
const prioRequestsProcessing = config.prioRequestsProcessing ?? true
server.prioRequestsProcessing =
prioRequestsProcessing && (server instanceof httpServer || server instanceof httpsServer)
if (server.prioRequestsProcessing) {
server.on('request', (req, res) => {
setImmediate(() => router.lookup(req, res))
})
} else {
server.on('request', (req, res) => {
router.lookup(req, res)
})
}
return {
router,
server
}
}