-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (50 loc) · 1.17 KB
/
server.js
File metadata and controls
55 lines (50 loc) · 1.17 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
const fastify = require('fastify')({
logger: true
})
fastify.register(require('fastify-swagger'), {
swagger: {
info: {
title: 'Test swagger',
description: 'testing the fastify swagger api',
version: '0.1.0'
},
securityDefinitions: {
apiKey: {
type: 'apiKey',
name: 'apiKey',
in: 'header'
}
}
},
exposeRoute: true,
routePrefix: '/documentations'
})
//decorator
fastify.decorateRequest('user', function () {
// something very useful
})
// Hook
// Update our property
fastify.addHook('preHandler', (req, reply, next) => {
var apiKey = req.headers.jwt;
if (apiKey == '1'){
req.user = 'anuj'
} else {
req.user = 'prasanth'
}
next()
})
fastify.use(require('cors')())
fastify.register(require('./routes'));
const config = require('config');
let id = '2'
let url = config.get('END_POINT_URL') + '?id=' + id
console.log(url);
// Run the server!
fastify.listen(3000, function (err, address) {
if (err) {
fastify.log.error(err)
process.exit(1)
}
fastify.log.info(`server listening on ${address}`)
})