File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 } ` ;
314const escapedApiBase = JSON . stringify ( apiBase ) . slice ( 1 , - 1 ) ;
415
516const 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 } ` ) ;
You can’t perform that action at this time.
0 commit comments