mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
Add backend framework selection between hono, elysiajs
This commit is contained in:
27
apps/cli/template/with-elysia/apps/server/src/index.ts
Normal file
27
apps/cli/template/with-elysia/apps/server/src/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import "dotenv/config";
|
||||
import { Elysia } from "elysia";
|
||||
import { cors } from "@elysiajs/cors";
|
||||
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"],
|
||||
}),
|
||||
)
|
||||
.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`);
|
||||
});
|
||||
13
apps/cli/template/with-elysia/apps/server/src/lib/context.ts
Normal file
13
apps/cli/template/with-elysia/apps/server/src/lib/context.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import type { Context as ElysiaContext } from "elysia";
|
||||
|
||||
export type CreateContextOptions = {
|
||||
context: ElysiaContext;
|
||||
};
|
||||
|
||||
export async function createContext({ context }: CreateContextOptions) {
|
||||
return {
|
||||
session: null,
|
||||
};
|
||||
}
|
||||
|
||||
export type Context = Awaited<ReturnType<typeof createContext>>;
|
||||
Reference in New Issue
Block a user