-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (44 loc) · 1.05 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
import fastifyLib from 'fastify';
import fastifyStatic from 'fastify-static';
import path from 'path';
import fastifyCloudVariable from './server/fastify-cloud-variables';
const fastify = fastifyLib({ logger: true });
fastify.register(
require('fastify-mongoose-driver'),
{
uri: 'mongodb://localhost:32768/sample-app-database',
settings: {
useNewUrlParser: true,
config: {
autoIndex: true
}
},
models: [],
useNameAndAlias: true
},
(err) => {
if (err) throw err;
}
);
fastify.register(fastifyStatic, {
root: path.join(__dirname, 'static')
//prefix: "/public/" // optional: default '/'
});
fastify.register(fastifyCloudVariable, {
x: 'y'
});
// Declare a route
fastify.get('/hello', async (request, reply) => {
return { hello: 'world' };
});
// Run the server!
const start = async () => {
try {
await fastify.listen(3000, '0.0.0.0');
fastify.log.info(`server listening on ${fastify.server.address().port}`);
} catch (err) {
fastify.log.error(err);
process.exit(1);
}
};
start();