- Remove Bunserver and just use buns type
All checks were successful
Code quality checks / biome (push) Successful in 10s
All checks were successful
Code quality checks / biome (push) Successful in 10s
- Stop logging every start aswell as available routes
This commit is contained in:
parent
69f0c3d8e9
commit
2eebc3126a
5 changed files with 18 additions and 21 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,5 @@
|
||||||
/node_modules
|
/node_modules
|
||||||
bun.lock
|
bun.lock
|
||||||
robots.txt
|
|
||||||
logs
|
logs
|
||||||
public/custom
|
public/custom
|
||||||
|
.env
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { echo } from "@atums/echo";
|
import { Echo, echo } from "@atums/echo";
|
||||||
import { environment } from "@config";
|
import { environment } from "@config";
|
||||||
import {
|
import {
|
||||||
type BunFile,
|
type BunFile,
|
||||||
|
@ -37,12 +37,15 @@ class ServerHandler {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
echo.info(`Server running at http://${server.hostname}:${server.port}`);
|
const echoChild = new Echo({ disableFile: true });
|
||||||
|
|
||||||
this.logRoutes();
|
echoChild.info(
|
||||||
|
`Server running at http://${server.hostname}:${server.port}`,
|
||||||
|
);
|
||||||
|
this.logRoutes(echoChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
private logRoutes(): void {
|
private logRoutes(echo: Echo): void {
|
||||||
echo.info("Available routes:");
|
echo.info("Available routes:");
|
||||||
|
|
||||||
const sortedRoutes: [string, string][] = Object.entries(
|
const sortedRoutes: [string, string][] = Object.entries(
|
||||||
|
@ -122,7 +125,7 @@ class ServerHandler {
|
||||||
|
|
||||||
private async handleRequest(
|
private async handleRequest(
|
||||||
request: Request,
|
request: Request,
|
||||||
server: BunServer,
|
server: Server,
|
||||||
): Promise<Response> {
|
): Promise<Response> {
|
||||||
const extendedRequest: ExtendedRequest = request as ExtendedRequest;
|
const extendedRequest: ExtendedRequest = request as ExtendedRequest;
|
||||||
extendedRequest.startPerf = performance.now();
|
extendedRequest.startPerf = performance.now();
|
||||||
|
|
14
types/bun.d.ts
vendored
14
types/bun.d.ts
vendored
|
@ -1,14 +0,0 @@
|
||||||
import type { Server } from "bun";
|
|
||||||
|
|
||||||
type Query = Record<string, string>;
|
|
||||||
type Params = Record<string, string>;
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
type BunServer = Server;
|
|
||||||
|
|
||||||
interface ExtendedRequest extends Request {
|
|
||||||
startPerf: number;
|
|
||||||
query: Query;
|
|
||||||
params: Params;
|
|
||||||
}
|
|
||||||
}
|
|
2
types/routes.d.ts
vendored
2
types/routes.d.ts
vendored
|
@ -9,7 +9,7 @@ type RouteModule = {
|
||||||
handler: (
|
handler: (
|
||||||
request: Request | ExtendedRequest,
|
request: Request | ExtendedRequest,
|
||||||
requestBody: unknown,
|
requestBody: unknown,
|
||||||
server: BunServer,
|
server: Server,
|
||||||
) => Promise<Response> | Response;
|
) => Promise<Response> | Response;
|
||||||
routeDef: RouteDef;
|
routeDef: RouteDef;
|
||||||
};
|
};
|
||||||
|
|
8
types/server.d.ts
vendored
Normal file
8
types/server.d.ts
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
type Query = Record<string, string>;
|
||||||
|
type Params = Record<string, string>;
|
||||||
|
|
||||||
|
interface ExtendedRequest extends Request {
|
||||||
|
startPerf: number;
|
||||||
|
query: Query;
|
||||||
|
params: Params;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue