forked from no-turno/gyoza-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.ts
56 lines (47 loc) · 1.37 KB
/
server.ts
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Elysia } from "elysia";
import { handler } from "@/app/entry.server";
import { default as Index } from "@/app/routes/api/index";
import { treaty } from "@elysiajs/eden";
import { swagger } from "@elysiajs/swagger";
import { staticPlugin } from "@elysiajs/static";
import { cors } from "@elysiajs/cors"
const isProd = process.env.NODE_ENV === "production";
const port = isProd ? 8080 : 3000;
const hostname = isProd ? "0.0.0.0" : "127.0.0.1";
export const Api = () =>
new Elysia({
prefix: "/api",
})
.use(swagger())
.use(Index);
export type API = ReturnType<typeof Api>;
export const App = () => treaty<API>(hostname + ":" + port);
const publicAssets = () =>
staticPlugin({
assets: "public",
noCache: true,
alwaysStatic: false,
directive: "public",
});
const distMain = () => Bun.file("dist/client/main.js");
const favicon = () => Bun.file("public/favicon.ico");
const app = () =>
new Elysia()
.use(cors())
.use(publicAssets())
.use(Api())
.get("/favicon.ico", favicon)
.get("/_dist/main.js", distMain)
.all("*", handler)
.listen(
{
hostname: hostname,
port: port,
},
(server) => {
console.log("%s", server.url);
},
);
if (process.isBun) {
app();
}