OpenAuth_server/src/index.ts

91 lines
2.7 KiB
TypeScript
Raw Normal View History

import Logging from "@hibas123/nodelogging";
import config from "./config";
2019-12-16 13:02:51 +00:00
// import NLS from "@hibas123/nodeloggingserver_client";
// if (config.logging) {
// let s = NLS(Logging, config.logging.server, config.logging.appid, config.logging.token);
// s.send(`[${new Date().toLocaleTimeString()}] Starting application`);
// }
// if (!config.database) {
// Logging.error("No database config set. Terminating.")
// process.exit();
// }
if (!config.web) {
2020-08-07 14:16:39 +00:00
Logging.error("No web config set. Terminating.");
process.exit();
}
2020-08-07 14:16:39 +00:00
import * as i18n from "i18n";
i18n.configure({
locales: ["en", "de"],
directory: "./locales",
2020-08-07 14:16:39 +00:00
});
import Web from "./web";
import TestData from "./testdata";
import DB from "./database";
2020-08-07 14:16:39 +00:00
Logging.log("Connecting to Database");
2019-12-16 13:02:51 +00:00
if (config.core.dev) {
2020-08-07 14:16:39 +00:00
Logging.warning("Running in dev mode! Database will be cleared!");
}
2020-08-07 14:16:39 +00:00
DB.connect()
.then(async () => {
Logging.log("Database connected");
if (config.core.dev) await TestData();
let web = new Web(config.web);
web.listen();
2020-08-07 14:16:39 +00:00
let already = new Set();
function print(path, layer) {
if (layer.route) {
layer.route.stack.forEach(
print.bind(null, path.concat(split(layer.route.path)))
);
} else if (layer.name === "router" && layer.handle.stack) {
layer.handle.stack.forEach(
print.bind(null, path.concat(split(layer.regexp)))
);
} else if (layer.method) {
let me: string = layer.method.toUpperCase();
me += " ".repeat(6 - me.length);
let msg = `${me} /${path
.concat(split(layer.regexp))
.filter(Boolean)
.join("/")}`;
if (!already.has(msg)) {
already.add(msg);
Logging.log(msg);
}
}
}
2020-08-07 14:16:39 +00:00
function split(thing) {
if (typeof thing === "string") {
return thing.split("/");
} else if (thing.fast_slash) {
return "";
} else {
var match = thing
.toString()
.replace("\\/?", "")
.replace("(?=\\/|$)", "$")
.match(
/^\/\^((?:\\[.*+?^${}()|[\]\\\/]|[^.*+?^${}()|[\]\\\/])*)\$\//
);
return match
? match[1].replace(/\\(.)/g, "$1").split("/")
: "<complex:" + thing.toString() + ">";
}
}
2020-08-07 14:16:39 +00:00
// Logging.log("--- Endpoints: ---");
// web.server._router.stack.forEach(print.bind(null, []))
// Logging.log("--- Endpoints end ---")
})
.catch((e) => {
Logging.error(e);
process.exit();
});