// serve.you — the Younasoft website, served by YOUNA itself. // // node cli/youna.ts run serve.you (run from the site root) // node cli/youna.ts run serve.you --deny ... // // Same rules as server.js: root files + images/ + assets/ only — // product folder source code is never served. Binary files stream // through as raw bytes so images and icons survive intact. permission network permission filesystem let ROOT = "." let PORT = 8790 let MIME = { html: "text/html; charset=utf-8", css: "text/css; charset=utf-8", js: "text/javascript; charset=utf-8", json: "application/json; charset=utf-8", webmanifest: "application/manifest+json", txt: "text/plain; charset=utf-8", you: "text/plain; charset=utf-8", png: "image/png", ico: "image/x-icon", svg: "image/svg+xml", jpg: "image/jpeg", jpeg: "image/jpeg", bmp: "image/bmp", gif: "image/gif", webp: "image/webp" } let ASSET_DIRS = ["images", "assets", "img", "public"] let BINARY_EXT = ["png", "ico", "svg", "jpg", "jpeg", "bmp", "gif", "webp"] function extOf(path) { let parts = split(path, ".") if len(parts) < 2 { return "" } return lower(parts[len(parts) - 1]) } function inList(xs, v) { for x in xs { if x == v { return true } } return false } // Path safety: no "..", no backslashes, subpaths only inside // whitelisted asset directories — exactly like server.js. function resolveFile(path) { if path == "/" { path = "/index.html" } if path == "/favicon.ico" { path = "/images/favicon.ico" } // the scanner runs out-of-band (node scan.js); serve the snapshot // so /api/products answers like the Node server does if path == "/api/products" { path = "/products.json" } if contains(path, "..") || contains(path, "\\") { return null } let rel = slice(path, 1) let parts = split(rel, "/") if len(parts) > 1 && !inList(ASSET_DIRS, parts[0]) { return null } for p in parts { if p == "" || p == "." { return null } } let full = ROOT + "/" + rel if !file_exists(full) { return null } return full } // Binary files: read raw bytes through a stream, return Array. // http_serve accepts a byte array body verbatim. function readBytes(full) { let s = stream_open(full) let bytes = [] while !stream_eof(s) { let chunk = stream_read(s, 65536) if chunk == null { break } for b in chunk { push(bytes, b) } } stream_close(s) return bytes } function router(req) { let path = req["path"]! let full = resolveFile(path) if full == null { return { status: 404, headers: {"Content-Type": "text/plain; charset=utf-8", "X-Powered-By": "YOUNA"}, body: "Not found" } } let e = extOf(full) let mime = MIME[e] ?? "application/octet-stream" let head = {"Content-Type": mime, "Cache-Control": "no-cache", "X-Powered-By": "YOUNA"} if inList(BINARY_EXT, e) { return {status: 200, headers: head, body: readBytes(full)} } return {status: 200, headers: head, body: read_file(full)} } let server = http_serve(router, PORT, "127.0.0.1") print("Younasoft site, served by YOUNA -> http://127.0.0.1:{http_port(server)}")