-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
96 lines (86 loc) · 1.89 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Require the framework and instantiate it
const fastify = require('fastify')({ logger: false })
var handler = require('./userHandling');
var jsonWorker = require('./jsonWorker');
var database = require('./databaseHandler');
/**
* @type {import('fastify').RouteShorthandOptions}
* @const
*/
const new_subscription = {
schema: {
response: {
200: {
type: 'object',
properties: {
distributor_url: { type: 'string' },
geocode: { type: 'String' }
}
}
}
}
}
const updated_subscription = {
schema: {
response: {
200: {
type: 'object',
properties: {
distributor_url: { type: 'string' },
new_geocodes: { type: 'array' },
remove_geocodes: { type: 'array' }
}
}
}
}
}
const remove_subscription = {
schema: {
response: {
200: {
type: 'object',
properties: {
distributor_url: { type: 'string' },
reason: { type: 'String' },
}
}
}
}
}
// Declare a route
fastify.get('/', async (request, reply) => {
reply
.code(200)
.type('text/html')
.send('<h1>Hello World</h1>')
console.log(request.body);
return { hello: 'world' }
})
fastify.post('/registration', {new_subscription}, async (request, reply) => {
handler.registration(request);
return { status: 'success' }
})
fastify.post('/update', {updated_subscription}, async (request, reply) => {
handler.update(request);
return { status: 'success' }
})
fastify.post('/remove', {remove_subscription}, async (request, reply) => {
handler.remove(request);
return { status: 'success' }
})
// Run the server!
const start = async () => {
try {
await fastify.listen({ port: 3000 })
} catch (err) {
fastify.log.error(err)
process.exit(1)
}
}
// start the server
start()
/*setInterval(
jsonWorker.loadJson
, 3000
);*/
// jsonWorker.loadJson()