17 lines
760 B
JavaScript
17 lines
760 B
JavaScript
// Runs the transformer handler (written for Vercel's req/res helpers) on Node's http server.
|
|
import { createServer } from "node:http";
|
|
import handler from "./transformer.js";
|
|
|
|
createServer(async (req, res) => {
|
|
const url = new URL(req.url, "http://localhost");
|
|
if (url.pathname === "/health") return res.writeHead(200).end("ok");
|
|
if (url.pathname !== "/api/transformer") return res.writeHead(404).end("Not found");
|
|
req.query = {};
|
|
for (const key of new Set(url.searchParams.keys())) {
|
|
const values = url.searchParams.getAll(key);
|
|
req.query[key] = values.length > 1 ? values : values[0];
|
|
}
|
|
res.status = (code) => ((res.statusCode = code), res);
|
|
res.send = (body) => res.end(body);
|
|
await handler(req, res);
|
|
}).listen(8000, "0.0.0.0");
|