import { esc, html, json, page } from "./lib/http.mjs"; import { catalog } from "./catalog.mjs"; import { CartError, quote } from "./cart.mjs"; const home = () => `

Пион

Цветы с доставкой по Алматы. Доставка бесплатно от 5 000 ₸.

`; export const routes = [ { method: "GET", path: "/healthz", handler: ({ res }) => { res.writeHead(200, { "content-type": "text/plain; charset=utf-8" }); res.end("ok"); }, }, { method: "GET", path: "/", handler: ({ res }) => html(res, page("Пион — цветы", home())) }, { // Расчёт заказа: { items: [{ sku, qty }], promo? } → { subtotal, discount, delivery, total }. method: "POST", path: "/api/quote", async handler({ res, body }) { const b = await body(); try { json(res, 200, quote(b.items, b.promo)); } catch (e) { if (e instanceof CartError) return json(res, 400, { errors: { items: e.message } }); throw e; } }, }, ];