DenReg/registry/src/http.ts

64 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-01-11 14:06:02 +00:00
// /// <reference path="./types/jsx.d.ts" />
2020-10-14 00:52:02 +00:00
import { ABC, CorsMW, LoggerMW, Path } from "./deps.ts";
2020-07-28 12:39:54 +00:00
import config from "./config.ts";
const port = config?.api?.port || 8000;
const app = new ABC.Application();
app.use(LoggerMW.logger({}));
app.use(CorsMW.cors({}));
2020-10-14 00:52:02 +00:00
// app.static("/public", "./public");
const MIMEDB = {
".css": "text/css",
".json": "application/json",
".js": "application/javascript",
".gz": "applcation/gzip",
".ico": "image/x-icon",
".png": "image/png",
".svg": "image/svg+xml",
".xml": "application/xml",
};
app.get("/public/*path", async (ctx) => {
const filePath = Path.join("./public", ctx.params.path);
console.log(filePath);
ctx.blob(
await Deno.open(filePath, { read: true }),
(MIMEDB as any)[Path.extname(filePath)]
);
});
2020-07-28 12:39:54 +00:00
import api from "./http/api.ts";
api(app.group("/api"));
2020-07-28 12:39:54 +00:00
import raw from "./http/raw.ts";
raw(app.group("/raw"));
2020-07-28 12:39:54 +00:00
import intellisense from "./http/intellisense.ts";
intellisense(app.group("/.well-known"));
2020-07-29 18:47:36 +00:00
import view from "./http/views.ts";
view(app);
2020-10-14 00:52:02 +00:00
// function logNode(router: Node, indent = 0) {
// trees.map((tree) => {
// console.log("Path:", tree.path);
// tree.children?.forEach((node) => logNode(node, indent + 3));
// });
// }
// const trees = Object.values(app.router) as Node[];
// trees.forEach(logNode);
2020-07-29 18:47:36 +00:00
import render from "./renderer.tsx";
app.renderer = {
render: render,
};
2020-07-28 12:39:54 +00:00
app.start({ port });
console.log("Running server at http://0.0.0.0:" + port);
console.log("Open at http://127.0.0.1:" + port);