diff options
Diffstat (limited to 'src/web.mjs')
-rw-r--r-- | src/web.mjs | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/src/web.mjs b/src/web.mjs index 8eed5b4..cd875a0 100644 --- a/src/web.mjs +++ b/src/web.mjs @@ -1,30 +1,18 @@ -import http from "node:http"; +import * as u from "./utils.mjs"; +import { buildServer, defaultInterceptors } from "./hero.mjs"; -const listProducts = () => {}; -const getProduct = () => {}; -const routes = { - GET: { - "/products": listProducts, - "/products/:id": getProduct, - }, -}; +const listProducts = req => ({ status: 200 }); +const getProduct = req => ({ status: 200 }); +const getChat = req => ({ status: 200, body: "something\n" }); -const server = http.createServer((req, res) => { - const { headers ,url, method } = req; - console.log({ - headers, - url, - method, - }); - res.writeHead(200, { - "Content-Type": "text/plain", - }); - res.end("Hello, web!\n"); -}); +const server = buildServer([ + [ "GET", "/products", listProducts ], + [ "GET", "/products/:id", getProduct ], + [ "GET", "/chat", getChat ], +], defaultInterceptors); -export const app = udsPath => { - server.listen(udsPath, () => { - console.log("I'm web."); - }); +export const app = async udsPath => { + await server.listen(udsPath); + u.log({ type: "starting-server", udsPath }); }; |