40 lines
783 B
TypeScript
40 lines
783 B
TypeScript
import Fastify from "fastify"
|
|
import cors from "@fastify/cors"
|
|
import cookie from "@fastify/cookie"
|
|
import jwt from "@fastify/jwt"
|
|
import { setupRoutes } from "./routes/index"
|
|
|
|
const server = Fastify({
|
|
logger: true
|
|
})
|
|
|
|
const PORT = Number(process.env.PORT) || 4001
|
|
const HOST = "0.0.0.0"
|
|
|
|
async function start() {
|
|
await server.register(cors, {
|
|
origin: "http://localhost:5174",
|
|
credentials: true
|
|
})
|
|
|
|
await server.register(cookie)
|
|
|
|
await server.register(jwt, {
|
|
secret: process.env.JWT_SECRET || "dev-secret-change-me"
|
|
})
|
|
|
|
server.get("/health", async () => {
|
|
return { status: "ok" }
|
|
})
|
|
|
|
await setupRoutes(server)
|
|
|
|
try {
|
|
await server.listen({ port: PORT, host: HOST })
|
|
} catch (err) {
|
|
server.log.error(err)
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
start() |