Skip to content

Commit 439924d

Browse files
update demos task to use env, serve the api in serve.ts
Signed-off-by: Jason McCallister <jason@mccallister.dev>
1 parent 11c0ae1 commit 439924d

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

serve.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
1-
const apiBase = Deno.env.get("API_BASE") ?? "http://localhost:5173";
1+
// always import from jsr:@snaapi/snaapi to ensure the correct version is used, even if the package is installed locally
2+
import { Snaapi } from "jsr:@snaapi/snaapi@0.11.0";
23

4+
const apiPort = Number(Deno.env.get("API_PORT") ?? "8000");
5+
const sitePort = Number(Deno.env.get("SITE_PORT") ?? "8080");
6+
7+
// Start the Snaapi API
8+
const app = await Snaapi.app();
9+
await app.listen({ port: apiPort });
10+
console.log(`Snaapi API running on http://localhost:${apiPort}`);
11+
12+
// Serve the demo site with the API base URL injected
13+
const apiBase = Deno.env.get("API_BASE") ?? `http://localhost:${apiPort}`;
314
const escapedApiBase = JSON.stringify(apiBase).slice(1, -1);
415

516
const html = (
617
await Deno.readTextFile(new URL("./index.html", import.meta.url))
718
).replace("__API_BASE__", escapedApiBase);
819

9-
Deno.serve({ port: 8080 }, (_req) => {
20+
Deno.serve({ port: sitePort }, (_req) => {
1021
return new Response(html, {
1122
headers: { "content-type": "text/html; charset=utf-8" },
1223
});
1324
});
25+
26+
console.log(`Snaapi Homes site running on http://localhost:${sitePort}`);

0 commit comments

Comments
 (0)