gemma: generate apps/api/src/index.ts
This commit is contained in:
parent
1025675f4f
commit
bb7e19c3e0
41
apps/api/src/index.ts
Normal file
41
apps/api/src/index.ts
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import "dotenv/config"
|
||||||
|
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()
|
||||||
Loading…
Reference in New Issue
Block a user