feat(static): embed labdb/public/* and serve from BridgeDispatch
Drops labdb's index.html / login.html / css / js into the binary via
embed.FS so the single 24 MB fivenode_go binary now ships both the
HTML/JS frontend AND the JSON API. No web server, no Apache,
no asset bundler.
hbrtl_ext/labdb_static/
public/ mirror of fivenode/labdb/public/
assets.go //go:embed public + two PRG-callable
HB_FUNCs: LABDB_STATIC_FILE(cPath) returns
the bytes, LABDB_STATIC_MIME(cPath)
returns the Content-Type derived from
the resolved (not raw) extension so "/"
-> text/html, not application/octet-stream.
app/bridge_server.prg
BridgeDispatch now falls through to the static FS for any path
that isn't /api/*. Missing assets get a 404 instead of being
routed to the path-to-symbol dispatcher.
Verified:
GET / -> 200 text/html, full index.html body
GET /login.html -> 200 text/html, 1850 bytes
GET /css/app.css -> 200 text/css
GET /api/admin-stats -> 200 JSON {devices:2,...} (still live PG)
GET /nonexistent.html -> 404 text/plain
Phase 1a complete: HTTP serves both the labdb frontend and the
real-data labdb API from one binary, end to end.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,23 @@ FUNCTION Main()
|
||||
RETURN NIL
|
||||
|
||||
FUNCTION BridgeDispatch( hReq )
|
||||
LOCAL hCtx, cFunc, cErr
|
||||
LOCAL hCtx, cFunc, cErr, cStatic, cMime
|
||||
|
||||
// Static file fallback: anything that isn't /api/* is served from
|
||||
// the embedded labdb/public/ filesystem. Lets index.html / login.html
|
||||
// / css / js ship in the same binary as the JSON API.
|
||||
IF SubStr( hReq[ "path" ], 1, 5 ) != "/api/"
|
||||
cStatic := LABDB_STATIC_FILE( hReq[ "path" ] )
|
||||
IF ! Empty( cStatic )
|
||||
cMime := LABDB_STATIC_MIME( hReq[ "path" ] )
|
||||
RETURN { ;
|
||||
"status" => 200, ;
|
||||
"headers" => { "Content-Type" => cMime }, ;
|
||||
"body" => cStatic ;
|
||||
}
|
||||
ENDIF
|
||||
RETURN { "status" => 404, "headers" => { "Content-Type" => "text/plain" }, "body" => "404: " + hReq[ "path" ] }
|
||||
ENDIF
|
||||
|
||||
hCtx := { ;
|
||||
"method" => hReq[ "method" ], ;
|
||||
|
||||
Reference in New Issue
Block a user