-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (31 loc) · 998 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
import Fastify from 'fastify'
import moesif from 'moesif-nodejs';
import FastifyMiddie from '@fastify/middie';
const fastify = Fastify({
logger: true
})
// you must register @fastify/middie or @fastify/express in order to use any express style middleware.
// https://fastify.dev/docs/latest/Reference/Middleware/#middleware
await fastify.register(FastifyMiddie)
const moesifOptions = {
applicationId: 'Your Application Id',
debug: true,
// add other options, see available options from moesif nodejs docs:
// https://github.com/Moesif/moesif-nodejs#configuration-options
};
const moesifMiddleware = moesif(moesifOptions);
fastify.use(moesifMiddleware);
// Declare a route
fastify.get('/', async function handler (request, reply) {
return { hello: 'world' }
})
fastify.post('/random', async function handler (request, reply) {
return { foo: 'bar' }
})
// Run the server!
try {
await fastify.listen({ port: 3050 })
} catch (err) {
fastify.log.error(err)
process.exit(1)
}