Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api/Endpoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default class Endpoint {
constructor(path, method, handler) {
this.path = path;
this.method = method;
this.handler = handler;
}
}
40 changes: 40 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import HTTP from "node:http";
import Endpoint from "./Endpoint.js";
import { joinMapJStoMarkdown } from "../index.js";

const host = "localhost";
const port = 8000;
const endpoints = [];

const requestListener = function (req, res) {
endpoints.forEach((endpoint) => {
if (endpoint.path === req.url && endpoint.port === req.port) {
endpoint.handler(req, res);
}
});
};

const server = HTTP.createServer(requestListener);
server.keepAlive = true;
server.listen(port, host, () => {
console.log(`Server is running on http://${host}:${port}`);
});

const index = new Endpoint("/", "POST", (req, res) => {
var body = "";
req.on("data", function (data) {
body += data;

// Too much POST data, kill the connection!
// 1e6 === 1 * Math.pow(10, 6) === 1 * 1000000 ~~~ 1MB
if (body.length > 1e6) request.connection.destroy();
});

req.on("end", function () {
const ret = joinMapJStoMarkdown(body);
res.setHeader("Content-Type", "plain/text");
res.writeHead(200);
res.end(ret);
});
});
endpoints.push(index);
Empty file added api/index.test.js
Empty file.
30 changes: 30 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": []
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
}
}
8 changes: 0 additions & 8 deletions eslint.config.js

This file was deleted.

Loading