-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
42 lines (35 loc) · 965 Bytes
/
index.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
const path = require('path');
const config = require('./config');
const fastify = require('fastify')();
// compression - add x-protobuf
fastify.register(
require('fastify-compress'), {
customTypes: /^text\/|\+json$|\+text$|\+xml|x-protobuf$/
}
);
// CORS
fastify.register(require('fastify-cors'));
// swagger documentation
fastify.register(require('fastify-swagger'), {
exposeRoute: true,
swagger: config.swagger
});
fastify.get('/map', {schema: {hide: true}}, (req, reply) => {
reply.sendFile('ol.html');
});
fastify.register(require('fastify-static'), {
root: path.join(__dirname, 'public'),
prefix: '/',
});
// routes
fastify.register(require('fastify-autoload'), {
dir: path.join(__dirname, 'routes')
});
// Launch server
fastify.listen(config.server.port, (config.server.host || 'localhost'), function (err, address) {
if (err) {
console.log(err);
process.exit(1);
}
console.info(`Server listening on ${address}`);
});