initial commit
This commit is contained in:
commit
33e75c056f
77 changed files with 4329 additions and 0 deletions
37
apps/server/src/index.ts
Normal file
37
apps/server/src/index.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { cors } from "@elysiajs/cors";
|
||||
import { createContext } from "@minmon/api/context";
|
||||
import { appRouter } from "@minmon/api/routers/index";
|
||||
import { auth } from "@minmon/auth";
|
||||
import { env } from "@minmon/env/server";
|
||||
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
||||
import { Elysia } from "elysia";
|
||||
|
||||
const app = new Elysia()
|
||||
.use(
|
||||
cors({
|
||||
origin: env.CORS_ORIGIN,
|
||||
methods: ["GET", "POST", "OPTIONS"],
|
||||
allowedHeaders: ["Content-Type", "Authorization"],
|
||||
credentials: true,
|
||||
}),
|
||||
)
|
||||
.all("/api/auth/*", async (context) => {
|
||||
const { request, status } = context;
|
||||
if (["POST", "GET"].includes(request.method)) {
|
||||
return auth.handler(request);
|
||||
}
|
||||
return status(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");
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue