-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.ts
More file actions
27 lines (22 loc) · 795 Bytes
/
server.ts
File metadata and controls
27 lines (22 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { createRequestHandler } from "@remix-run/node";
import { join } from "node:path";
// @ts-expect-error - build output has no type declarations
import * as build from "./build/server/index.js";
const remixHandler = createRequestHandler(build, process.env.NODE_ENV);
const server = Bun.serve({
port: process.env.PORT || 3000,
async fetch(request) {
const url = new URL(request.url);
const path = join(process.cwd(), "public", url.pathname);
// 1. Serve Static Assets (Frontend)
if (url.pathname !== "/") {
const file = Bun.file(path);
if (await file.exists()) {
return new Response(file);
}
}
// 2. Serve Remix App (Backend/SSR)
return remixHandler(request);
},
});
console.log(`🚀 Server started on port ${server.port}`);