-
Notifications
You must be signed in to change notification settings - Fork 0
/
dev.js
36 lines (26 loc) 路 739 Bytes
/
dev.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
const dotenv = require('dotenv')
dotenv.config()
const createFastify = require('fastify')
const cookie = require('fastify-cookie')
const nuxt = require('fastify-nuxtjs')
const routes = require('./api/routes')
const main = async (req, res) => {
const { COOKIE_SECRET, SERVER_PORT } = process.env
const fastify = createFastify({ ignoreTrailingSlash: true })
const cookieOpts = {}
if (COOKIE_SECRET) {
cookieOpts.secret = COOKIE_SECRET
}
fastify.register(cookie, cookieOpts)
fastify.register(nuxt).after(() => {
fastify.nuxt('*')
})
routes(fastify)
const port = +SERVER_PORT || 3000
await fastify.ready()
await fastify.listen(port)
}
main().catch((err) => {
console.error(err)
process.exit(1)
})