- docs/examples/writeonce-serve -> docs/examples/porch (git mv, history kept); `[deps]` key and import are now `porch` / `porch/http` / `porch/router` - name history preserved on the library README, not rewritten into dated records: writeonce-framework -> writeonce-serve (08-25) -> porch (08-26). Stories, specs, plans and the audit reports keep the older name by the repo's own convention; only live docs and every path link were rewritten - left alone deliberately: `internal/serve.wo`, `pub fn serve`, `serve_conn`, `app.serve(...)` — those are functions, not the module name - web-app/wo.toml comment corrected: it claimed hyphens are not identifier characters and named a key this file never used. lexer.ml's `is_ident_cont` DOES accept `-` (an internal dash is part of the identifier, which is why binary minus needs spaces), so a hyphenated key would be legal too - site now teaches the name: package card, the two-deps chapter and the handlers-are-classes chapter say `porch`; site-accept asserted the old /packages/serve route and caught the rename, as a gate should - gates: web-app 46/0, site 21/0, deps-accept 8/0, oop-e2e 116/0, linkcheck 0 broken / 0 anchors; porch typechecks entry-less as kind=library Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
51 lines
1.7 KiB
Text
51 lines
1.7 KiB
Text
-- shop/main.wo — the bootstrap (app-routing.module's analog): seed the
|
|
-- store on first boot, wire routes to the feature controllers, serve.
|
|
-- No rendering and no queries here beyond the seed.
|
|
--
|
|
-- WO_DATA=./data ./target/shop 8080 (run from the shop directory:
|
|
-- /assets/* serves from ./assets)
|
|
use porch
|
|
use porch/http
|
|
use porch/router
|
|
use product_list
|
|
use product_page
|
|
use orders
|
|
|
|
fn seed_if_empty() {
|
|
let n = 0;
|
|
for p in from x in Product take 1 select x {
|
|
n = n + 1;
|
|
}
|
|
if n > 0 {
|
|
return;
|
|
}
|
|
insert Product { sku: "keyb-75", name: "75% mechanical keyboard", price: 89.0, stock: 12 };
|
|
insert Product { sku: "mug-wal", name: "WAL-backed coffee mug", price: 14.5, stock: 40 };
|
|
insert Product { sku: "tee-own", name: "Ownership-checked t-shirt", price: 24.9, stock: 25 };
|
|
insert Product { sku: "desk-pad", name: "Deskmat (one binary edition)", price: 19.0, stock: 0 };
|
|
}
|
|
|
|
fn main(args: multi Text) -> Int {
|
|
if len(args) < 1 {
|
|
print_err("usage: shop <port> (WO_DATA=<dir> makes the store durable)");
|
|
return 2;
|
|
}
|
|
let port = parse_int(args[0]);
|
|
if port == nil {
|
|
print_err("shop: <port> must be a number");
|
|
return 2;
|
|
}
|
|
|
|
seed_if_empty();
|
|
|
|
let app = App { middleware: [], routes: [] };
|
|
app.use_mw(Mw { m: Logging {} });
|
|
app.get("/", ListProducts {});
|
|
app.get("/p/:sku", ShowProduct {});
|
|
app.post("/orders/:sku", CreateOrder {});
|
|
app.get("/orders", ListOrders {});
|
|
-- the framework's file server (serve/http): 2 MiB ceiling is well
|
|
-- above this template's stylesheet.
|
|
app.get("/assets/*path", StaticFiles { dir: "assets", max_bytes: 2097152 });
|
|
return app.serve("127.0.0.1", port);
|
|
}
|