This commit is contained in:
Aman Varshney
2025-04-14 21:45:28 +05:30
parent 8b03441909
commit 7f441ef670
268 changed files with 3513 additions and 3039 deletions

View File

@@ -0,0 +1,78 @@
import "dotenv/config";
{{#if (eq api "trpc")}}
import { createExpressMiddleware } from "@trpc/server/adapters/express";
import { createContext } from "./lib/context";
import { appRouter } from "./routers/index";
{{/if}}
{{#if (eq api "orpc")}}
import { RPCHandler } from "@orpc/server/node";
import { appRouter } from "./routers";
{{/if}}
import cors from "cors";
import express from "express";
{{#if (includes examples "ai")}}
import { streamText } from "ai";
import { google } from "@ai-sdk/google";
{{/if}}
{{#if auth}}
import { auth } from "./lib/auth";
{{/if}}
const app = express();
app.use(
cors({
origin: process.env.CORS_ORIGIN || "",
methods: ["GET", "POST", "OPTIONS"],
{{#if auth}}
allowedHeaders: ["Content-Type", "Authorization"],
credentials: true,
{{/if}}
})
);
{{#if auth}}
app.all("/api/auth{/*path}", toNodeHandler(auth));
{{/if}}
{{#if (eq api "trpc")}}
app.use(
"/trpc",
createExpressMiddleware({
router: appRouter,
createContext
})
);
{{/if}}
{{#if (eq api "orpc")}}
const handler = new RPCHandler(appRouter);
app.use('/rpc{*path}', async (req, res, next) => {
const { matched } = await handler.handle(req, res, {
prefix: '/rpc',
context: {},
});
if (matched) return;
next();
});
{{/if}}
{{#if (includes examples "ai")}}
// AI chat endpoint
app.post("/ai", async (req, res) => {
const { messages = [] } = req.body;
const result = streamText({
model: google("gemini-1.5-flash"),
messages,
});
result.pipeDataStreamToResponse(res);
});
{{/if}}
app.get("/", (_req, res) => {
res.status(200).send("OK");
});
app.listen(3000, () => {
console.log("Server is running on port 3000");
});