-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (23 loc) · 744 Bytes
/
server.js
File metadata and controls
31 lines (23 loc) · 744 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
31
import http from 'http'
import { Log, httpLogs } from '../src/index.js'
const name = 'An App'
const logHttpMw = httpLogs()
const log = new Log('server')
const codes = [200, 200, 200, 404, 500]
const randomStatus = () => codes[(Math.random() * codes.length) | 0]
// fake app
log.info('booting %o', name)
http
.createServer(function (req, res) {
log.debug('%s %s', req.method, req.url)
logHttpMw(req, res, () => {})
const str = req.url.replace(/[/]/g, '')
res.statusCode = randomStatus()
// res.setHeader('Set-Cookie', ['foo=bar', 'session=foobar'])
res.setHeader('Set-Cookie', 'session=foobar')
res.end(`hello ${str}`)
})
.listen(3000, function () {
log.info('listening')
})
import('./client.js')