|
1 | | -import { createApp, type Response, type Request, type App, type NextFunction, type Handler } from "brahma-firelight"; |
| 1 | +import { createApp, type Response, type Request, type App, type NextFunction, type Handler, registerRustHotpath } from "brahma-firelight"; |
2 | 2 | import cluster from "node:cluster"; |
3 | 3 | import os from "node:os"; |
4 | 4 |
|
5 | 5 | const app: App = createApp(); |
6 | 6 |
|
7 | 7 | // Server Config Middleware |
8 | | -const serverInfo: Handler = (_req: Request, res: Response, next?: NextFunction) => { |
9 | | - res.setHeader("Server", "brahma-firelight"); |
10 | | - res.setHeader("Connection", "keep-alive") |
11 | | - next?.(); |
12 | | -}; |
| 8 | +// const serverInfo: Handler = (_req: Request, res: Response, next?: NextFunction) => { |
| 9 | +// res.setHeader("Server", "brahma-firelight"); |
| 10 | +// res.setHeader("Connection", "keep-alive") |
| 11 | +// next?.(); |
| 12 | +// }; |
13 | 13 |
|
14 | 14 | // JSON compute |
15 | | -app.get("/json", serverInfo, (_req: Request, res: Response) => { |
16 | | - res.json({ message: "Hello, World!" }); |
17 | | -}); |
| 15 | +// app.get("/json", serverInfo, (_req: Request, res: Response) => { |
| 16 | +// res.json({ message: "Hello, World!" }); |
| 17 | +// }); |
| 18 | + |
| 19 | +// PLAIN-TEXT |
| 20 | +// app.get("/plaintext", serverInfo, (_req: Request, res: Response) => { |
| 21 | +// res.text("Hello, World!"); |
| 22 | +// }); |
| 23 | + |
| 24 | + |
| 25 | +// JSON compute |
| 26 | +registerRustHotpath( |
| 27 | + "GET", |
| 28 | + "/json", |
| 29 | + 200, |
| 30 | + '{"Content-Type": "application/json", "Server": "brahma-firelight"}', |
| 31 | + Buffer.from(JSON.stringify({ message: "Hello, World!" })) |
| 32 | +); |
18 | 33 |
|
19 | 34 | // PLAIN-TEXT |
20 | | -app.get("/plaintext", serverInfo, (_req: Request, res: Response) => { |
21 | | - res.text("Hello, World!"); |
22 | | -}); |
| 35 | +registerRustHotpath( |
| 36 | + "GET", |
| 37 | + "/plaintext", |
| 38 | + 200, |
| 39 | + '{"Content-Type": "text/plain", "Server": "brahma-firelight"}', |
| 40 | + Buffer.from("Hello, World!") |
| 41 | +); |
23 | 42 |
|
24 | 43 | // Port & Host |
25 | 44 | const PORT = process.env.PORT || 8080; |
|
0 commit comments