27 lines
754 B
JavaScript
27 lines
754 B
JavaScript
import Fastify from 'fastify'
|
|
import cookie from '@fastify/cookie'
|
|
import cors from '@fastify/cors'
|
|
import { initDb } from './db.js'
|
|
import { authRoutes } from './routes/auth.js'
|
|
import { adminRoutes } from './routes/admin.js'
|
|
|
|
const app = Fastify({ logger: true, trustProxy: true })
|
|
|
|
await app.register(cookie)
|
|
await app.register(cors, {
|
|
origin: process.env.CORS_ORIGIN ? process.env.CORS_ORIGIN.split(',') : false,
|
|
credentials: true,
|
|
})
|
|
|
|
app.get('/health', async () => ({ status: 'healthy' }))
|
|
|
|
await app.register(authRoutes, { prefix: '/api/auth' })
|
|
await app.register(adminRoutes, { prefix: '/api/auth/admin' })
|
|
|
|
try {
|
|
await initDb()
|
|
await app.listen({ port: 3001, host: '0.0.0.0' })
|
|
} catch (err) {
|
|
app.log.error(err)
|
|
process.exit(1)
|
|
}
|