forked from neoxr/open-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
42 lines (37 loc) · 905 Bytes
/
server.js
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
32
33
34
35
36
37
38
39
40
41
42
global.creator = `mr.one`
const fastify = require('fastify')({
logger: true
})
fastify.register(require('fastify-log'))
fastify.register(require('fastify-prettier'), {
alwaysOn: true
})
fastify.addContentTypeParser('application/json', {
parseAs: 'string'
}, function(req, body, done) {
try {
const json = JSON.parse(body)
done(null, json)
} catch (err) {
err.statusCode = 400
done(err, undefined)
}
})
fastify.addContentTypeParser('*', function(request, payload, done) {
let data = ''
payload.on('data', chunk => {
data += chunk
})
payload.on('end', () => {
done(null, data)
})
})
fastify.register(require('./app'))
fastify.listen({
port: 3000,
host: '0.0.0.0',
backlog: 255
}, (err, address) => {
if (err) throw err
fastify.info(`Server is now listening on ${address}`)
})