oof
This commit is contained in:
@@ -2,19 +2,30 @@ import http from "http";
|
||||
import url from "url";
|
||||
import querystring from "querystring";
|
||||
import cfg from "../config.json";
|
||||
import router from "./inc/router.mjs";
|
||||
|
||||
// routes
|
||||
import "./inc/routes/index";
|
||||
import "./inc/routes/api";
|
||||
import "./inc/routes/index.mjs";
|
||||
import "./inc/routes/api.mjs";
|
||||
import "./inc/routes/static.mjs";
|
||||
|
||||
import { routes } from "./inc/router";
|
||||
|
||||
http.createServer((req, res, r) => {
|
||||
http.createServer(async (req, res, r) => {
|
||||
req.url = url.parse(req.url.replace(/(?!^.)(\/+)?$/, ''));
|
||||
req.url.split = req.url.pathname.split("/").slice(1);
|
||||
req.url.qs = querystring.parse(req.url.query);
|
||||
|
||||
console.log(`[${(new Date()).toLocaleTimeString()}] ${req.method} ${req.url.pathname}`);
|
||||
req.post = new Promise((resolve, _, data = "") => req
|
||||
.on("data", d => void (data += d))
|
||||
.on("end", () => void resolve(Object.fromEntries(Object.entries(querystring.parse(data)).map(([k, v]) => [k, decodeURIComponent(v)])))));
|
||||
|
||||
!(r = routes.getRegex(req.url.pathname, req.method)) ? res.writeHead(404).end(`404 - ${req.url.pathname}`) : r(req, res);
|
||||
}).listen(cfg.websrv.port, () => console.log(`f0ck is listening on port ${cfg.websrv.port}.`));
|
||||
res.reply = ({
|
||||
code = 200,
|
||||
type = "text/html",
|
||||
body
|
||||
}) => res.writeHead(code, { "Content-Type": `${type}; charset=utf-8` }).end(body);
|
||||
|
||||
!(r = router.routes.getRoute(req.url.pathname, req.method)) ? res.writeHead(404).end(`404 - ${req.url.pathname}`) : await r(req, res);
|
||||
console.log(`[${(new Date()).toLocaleTimeString()}] ${res.statusCode} ${req.method}\t${req.url.pathname}`);
|
||||
}).listen(cfg.websrv.port, () => setTimeout(() => {
|
||||
console.log(`f0ck is listening on port ${cfg.websrv.port}.`);
|
||||
}, 500));
|
||||
|
Reference in New Issue
Block a user