Skip to content

Commit

Permalink
feat: use random port by default (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuapp authored Dec 12, 2024
1 parent bcbb459 commit 6320940
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/md-to-pdf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { launch } from "@astral/astral";
import { DEFAULT_PORT, launchHttpServer } from "./utils/server.ts";
import { launchHttpServer } from "./utils/server.ts";
import type { MdToPdfOptions } from "./types.ts";

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

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

// Close the browser and the server
Expand Down
4 changes: 1 addition & 3 deletions src/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { extract } from "@std/front-matter/yaml";
import { parse } from "@std/yaml/parse";
import { join } from "@std/path";

export const DEFAULT_PORT = 33433;

await initMd4w("small");

/**
Expand Down Expand Up @@ -71,7 +69,7 @@ export function launchHttpServer(
return notFound();
};

return Deno.serve({ onListen: () => "", port: DEFAULT_PORT }, handler);
return Deno.serve({ onListen: () => "", port: 0 }, handler);
}

/**
Expand Down

0 comments on commit 6320940

Please sign in to comment.