diff options
author | EuAndreh <eu@euandre.org> | 2023-11-11 06:10:57 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-11-11 06:13:43 -0300 |
commit | e912b1945c0544f60a5f118f86742d9a7b1b66b7 (patch) | |
tree | 92d6e75a9bb2dada2f58dcbf4f9bd1180c30ed7b /src | |
parent | TODOs.md: Add #td-d27aca11-9449-bb0e-08cb-2a8ef9778a11 (diff) | |
download | papod-e912b1945c0544f60a5f118f86742d9a7b1b66b7.tar.gz papod-e912b1945c0544f60a5f118f86742d9a7b1b66b7.tar.xz |
src/{ircd,web}.js: Init stub servers
Diffstat (limited to 'src')
-rw-r--r-- | src/api.js | 17 | ||||
-rwxr-xr-x | src/cli.js | 2 | ||||
-rw-r--r-- | src/ircd.js | 16 | ||||
-rw-r--r-- | src/web.js | 34 |
4 files changed, 65 insertions, 4 deletions
@@ -1,14 +1,25 @@ const { eq } = require("./utils.js"); +const ircd = require("./ircd.js"); +const web = require("./web.js"); -const main = async () => { - if (process.argv.length !== 2) { +const main = () => { + if (process.argv.length === 3 && process.argv[2] === "-V") { console.log("papo 1970-01-01 0.1.0"); return; } + if (process.argv[2] === "ircd") { + ircd.app(process.argv[3]); + return; + } + + if (process.argv[2] === "web") { + web.app(process.argv[3]); + return; + } + console.log({ argv: process.argv, - eq: eq({a: 1}, {a: 1}), }); }; @@ -1,4 +1,4 @@ #!/usr/bin/env node const { main } = require("papo"); -(async () => await main())(); +main(); diff --git a/src/ircd.js b/src/ircd.js new file mode 100644 index 0000000..affc986 --- /dev/null +++ b/src/ircd.js @@ -0,0 +1,16 @@ +const net = require("node:net"); + +const server = net.createServer(socket => { + socket.write("olar\r\n"); + socket.pipe(socket); +}); + +const app = udsPath => { + server.listen(udsPath, () => { + console.log("I'm ircd."); + }); +}; + +module.exports = { + app, +}; diff --git a/src/web.js b/src/web.js new file mode 100644 index 0000000..bfa1807 --- /dev/null +++ b/src/web.js @@ -0,0 +1,34 @@ +const http = require("node:http"); + +const listProducts = () => {}; +const getProduct = () => {}; + +const routes = { + GET: { + "/products": listProducts, + "/products/:id": getProduct, + }, +}; + +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 app = udsPath => { + server.listen(udsPath, () => { + console.log("I'm web."); + }); +}; + +module.exports = { + app, +}; |