Add runtime selection feature between Bun and Node.js

This commit is contained in:
Aman Varshney
2025-03-26 01:40:39 +05:30
parent 45cd2fc113
commit 88afd53a4d
22 changed files with 10432 additions and 224 deletions

View File

@@ -3,15 +3,11 @@
"main": "src/index.ts",
"type": "module",
"scripts": {
"dev": "tsx watch src/index.ts",
"start": "node dist/src/index.js",
"build": "tsc && tsc-alias",
"dev:bun": "bun run --hot src/index.ts",
"check-types": "tsc --noEmit",
"compile": "bun build --compile --minify --sourcemap --bytecode ./src/index.ts --outfile server"
},
"dependencies": {
"@hono/node-server": "^1.14.0",
"@hono/trpc-server": "^0.3.4",
"@trpc/server": "^11.0.0",
"dotenv": "^16.4.7",
@@ -19,9 +15,7 @@
"zod": "^3.24.2"
},
"devDependencies": {
"tsc-alias": "^1.8.11",
"tsx": "^4.19.2",
"@types/node": "^22.13.11",
"tsc-alias": "^1.8.11",
"typescript": "^5.8.2"
}
}

View File

@@ -1,4 +1,3 @@
import { serve } from "@hono/node-server";
import { trpcServer } from "@hono/trpc-server";
import "dotenv/config";
import { Hono } from "hono";
@@ -12,30 +11,23 @@ const app = new Hono();
app.use(logger());
app.use(
"/*",
cors({
origin: process.env.CORS_ORIGIN || "",
allowMethods: ["GET", "POST", "OPTIONS"],
}),
"/*",
cors({
origin: process.env.CORS_ORIGIN || "",
allowMethods: ["GET", "POST", "OPTIONS"],
}),
);
app.use(
"/trpc/*",
trpcServer({
router: appRouter,
createContext: (_opts, hono) => {
return createContext({ hono });
},
}),
"/trpc/*",
trpcServer({
router: appRouter,
createContext: (_opts, hono) => {
return createContext({ hono });
},
}),
);
app.get("/", (c) => {
return c.text("OK");
});
serve({
fetch: app.fetch,
port: 3000,
}, (info) => {
console.log(`Server is running on http://localhost:${info.port}`)
return c.text("OK");
});