I can't be bothered to even explain what happene here
This commit is contained in:
66
src/main.ts
66
src/main.ts
@@ -1,11 +1,11 @@
|
||||
import Logging from "@proxnet/undead-logging";
|
||||
import * as Log from "@proxnet/undead-logging";
|
||||
import * as Config from "./config.ts";
|
||||
import { Application, Router } from "@oak/oak";
|
||||
// @ts-types = 'npm:@types/express'
|
||||
import express from "express";
|
||||
import { Redis } from "./db.ts";
|
||||
import { Discord } from "./discord.ts";
|
||||
import { APIUtils } from "./apiutils.ts";
|
||||
|
||||
const log = new Logging("Main");
|
||||
const log = new Log.default("Main");
|
||||
|
||||
log.i(`Starting Galvanic Corrosion..`);
|
||||
|
||||
@@ -15,16 +15,44 @@ if (typeof config == 'undefined') {
|
||||
log.e('Cannot start: Configuration is undefined');
|
||||
Deno.exit(1);
|
||||
}
|
||||
if (config.secrets.authSecret == Config.defaultConfig.secrets.authSecret) {
|
||||
log.e(`Cannot start: Auth secret is default. Please change 'secrets.authSecret' in 'config.json'`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
Log.MessageTypeVisibility.Network = config.logging.network;
|
||||
Log.MessageTypeVisibility.Debug = config.logging.debug;
|
||||
|
||||
const port = config.web.port;
|
||||
const host = config.web.host;
|
||||
|
||||
log.i(`Starting HTTP server on http://${host}:${port}`);
|
||||
|
||||
const abortController = new AbortController();
|
||||
const app = new Application();
|
||||
const app = express();
|
||||
|
||||
app.use(new Router().all('/', APIUtils.genericResponse(false, `${config?.public.serverName} - ${config?.public.motd}`)).routes());
|
||||
app.disable('etag');
|
||||
app.disable('x-powered-by');
|
||||
|
||||
app.use((rq: express.Request, rs: express.Response, nxt: express.NextFunction) => {
|
||||
rs.locals.auth = null;
|
||||
log.n(`${APIUtils.getSrcIpDefault(rq)} ${rq.method} ${rq.originalUrl}`);
|
||||
nxt();
|
||||
});
|
||||
|
||||
app.use('/', APIUtils.genericResponse(false, `${config?.public.serverName} - ${config?.public.motd}`));
|
||||
|
||||
// content routes
|
||||
const nameserverRouter = await import('./routes/nameserver.ts');
|
||||
const apiRouter = await import('./routes/api.ts');
|
||||
|
||||
app.use(nameserverRouter.route.path, nameserverRouter.route.router);
|
||||
app.use(apiRouter.route.path, apiRouter.route.router);
|
||||
|
||||
app.use((rq: express.Request, rs: express.Response) => {
|
||||
log.e(`${APIUtils.getSrcIpDefault(rq)} 404 ${rq.method} ${rq.url.toString()}`);
|
||||
rs.statusCode = 404;
|
||||
rs.json(APIUtils.genericResponseFormat(true, 'Endpoint not found. Check your syntax and/or method.'));
|
||||
});
|
||||
|
||||
try {
|
||||
log.i(`Connecting to Redis..`);
|
||||
@@ -35,18 +63,22 @@ try {
|
||||
}
|
||||
|
||||
try {
|
||||
app.listen({port: port, hostname: host, signal: abortController.signal });
|
||||
const http = app.listen(config.web.port, config.web.host, () => {
|
||||
log.n(`Listening on http://${config.web.host}`);
|
||||
|
||||
let shuttingDown = false;
|
||||
Deno.addSignalListener('SIGINT', () => {
|
||||
if (shuttingDown) return;
|
||||
shuttingDown = true;
|
||||
log.i(`Shutting down`);
|
||||
|
||||
http.close();
|
||||
http.removeAllListeners();
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
log.e(`Cannot start: Network could not be initalized. ${err}`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
Discord.login();
|
||||
|
||||
let shuttingDown = false;
|
||||
Deno.addSignalListener('SIGINT', () => {
|
||||
if (shuttingDown) return;
|
||||
shuttingDown = true;
|
||||
log.n(`Shutting down`);
|
||||
abortController.abort();
|
||||
});
|
||||
//Discord.login(); do not use for now
|
||||
Reference in New Issue
Block a user