Skip to content

Commit 6320940

Browse files
authored
feat: use random port by default (#10)
1 parent bcbb459 commit 6320940

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/md-to-pdf.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { launch } from "@astral/astral";
2-
import { DEFAULT_PORT, launchHttpServer } from "./utils/server.ts";
2+
import { launchHttpServer } from "./utils/server.ts";
33
import type { MdToPdfOptions } from "./types.ts";
44

55
/**
@@ -20,7 +20,7 @@ export async function mdToPdf(
2020
const server = launchHttpServer(path, options);
2121

2222
const browser = await launch();
23-
const page = await browser.newPage(`http://localhost:${DEFAULT_PORT}`);
23+
const page = await browser.newPage(`http://localhost:${server.addr.port}`);
2424
const pdf = await page.pdf();
2525

2626
// Close the browser and the server

src/utils/server.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { extract } from "@std/front-matter/yaml";
55
import { parse } from "@std/yaml/parse";
66
import { join } from "@std/path";
77

8-
export const DEFAULT_PORT = 33433;
9-
108
await initMd4w("small");
119

1210
/**
@@ -71,7 +69,7 @@ export function launchHttpServer(
7169
return notFound();
7270
};
7371

74-
return Deno.serve({ onListen: () => "", port: DEFAULT_PORT }, handler);
72+
return Deno.serve({ onListen: () => "", port: 0 }, handler);
7573
}
7674

7775
/**

0 commit comments

Comments
 (0)