Bind web dev server to port 3000
Simplify the web dev launcher to always use port 3000 and fix the dev:web script cwd invocation.
This commit is contained in:
parent
b8f9e585e9
commit
18366192b2
2 changed files with 2 additions and 55 deletions
|
|
@ -1,58 +1,5 @@
|
|||
type PortCheck = {
|
||||
port: number;
|
||||
available: boolean;
|
||||
};
|
||||
|
||||
const DEFAULT_PORTS = [3001, 3002, 3003, 3004, 3005];
|
||||
|
||||
const isAvailable = (port: number): PortCheck => {
|
||||
try {
|
||||
const probe = Bun.serve({
|
||||
port,
|
||||
fetch: () => new Response("ok")
|
||||
});
|
||||
probe.stop();
|
||||
return { port, available: true };
|
||||
} catch {
|
||||
return { port, available: false };
|
||||
}
|
||||
};
|
||||
|
||||
const parsePort = (value: string | undefined): number | null => {
|
||||
if (!value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const parsed = Number.parseInt(value, 10);
|
||||
if (!Number.isFinite(parsed) || parsed <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parsed;
|
||||
};
|
||||
|
||||
const selectPort = (): number => {
|
||||
const requested = parsePort(Bun.env.PORT);
|
||||
|
||||
if (requested !== null) {
|
||||
const check = isAvailable(requested);
|
||||
if (!check.available) {
|
||||
throw new Error(`Port ${requested} is already in use. Set PORT to another value.`);
|
||||
}
|
||||
return requested;
|
||||
}
|
||||
|
||||
for (const port of DEFAULT_PORTS) {
|
||||
if (isAvailable(port).available) {
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("No available port found for Next dev server.");
|
||||
};
|
||||
|
||||
const run = async () => {
|
||||
const port = selectPort();
|
||||
const port = 3000;
|
||||
console.log(`[web] starting Next.js dev server on port ${port}`);
|
||||
|
||||
const path = Bun.env.PATH ?? "";
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
"dev": "bun run scripts/dev.ts",
|
||||
"dev:infra": "docker compose up",
|
||||
"dev:infra:down": "docker compose down",
|
||||
"dev:web": "bun --cwd apps/web run dev",
|
||||
"dev:web": "bun --cwd=apps/web run dev",
|
||||
"dev:services": "bun run scripts/dev-services.ts"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue