Skip to content

Commit 4a4b119

Browse files
committed
refactor: streamline server start process and improve port handling
1 parent 45bd1f3 commit 4a4b119

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/pranx/src/cmd/start.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { OUTPUT_BUNDLE_BROWSER_DIR, PUBLIC_USER_DIR } from "@/build/constants.js";
22
import { logger } from "@/utils/logger.js";
3+
import { measureTime } from "@/utils/time-perf.js";
34
import fse from "fs-extra";
4-
import { checkPort, getRandomPort } from "get-port-please";
55
import { H3, serve, serveStatic } from "h3";
66
import kleur from "kleur";
77
import { readFile, stat } from "node:fs/promises";
@@ -10,10 +10,9 @@ import { join } from "node:path";
1010
export async function start() {
1111
logger.log(kleur.bold().magenta("Pranx Start"));
1212

13-
const DEFAULT_PORT = 3030;
14-
const isPortUsed = await checkPort(DEFAULT_PORT);
13+
measureTime("pranx-start");
1514

16-
const PORT = !isPortUsed ? await getRandomPort() : DEFAULT_PORT;
15+
const PORT = Number(process.env.PORT) || 3030;
1716

1817
const app = new H3();
1918

@@ -51,5 +50,11 @@ export async function start() {
5150
});
5251
});
5352

54-
serve(app, { port: PORT });
53+
const SERVER = serve(app, { port: PORT });
54+
55+
await SERVER.ready();
56+
57+
const START_TIME = measureTime("pranx-start");
58+
59+
logger.success(`Start in ${START_TIME} ms`);
5560
}

0 commit comments

Comments
 (0)