UNPKG

create-better-t-stack

Version:

A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations

38 lines (36 loc) 1.08 kB
import "dotenv/config"; import { Elysia } from "elysia"; import { cors } from "@elysiajs/cors"; import { auth } from "./lib/auth"; import { createContext } from "./lib/context"; import { appRouter } from "./routers/index"; import { fetchRequestHandler } from "@trpc/server/adapters/fetch"; const app = new Elysia() .use( cors({ origin: process.env.CORS_ORIGIN || "", methods: ["GET", "POST", "OPTIONS"], allowedHeaders: ["Content-Type", "Authorization"], credentials: true, }), ) .all("/api/auth/*", async (context) => { const { request } = context; if (["POST", "GET"].includes(request.method)) { return auth.handler(request); } context.error(405); }) .all("/trpc/*", async (context) => { const res = await fetchRequestHandler({ endpoint: "/trpc", router: appRouter, req: context.request, createContext: () => createContext({ context }), }); return res; }) .get("/", () => "OK") .listen(3000, () => { console.log("Server is running on http://localhost:3000"); });