Base utilities, add README, Redis, Discord integration, db keygroup planning
This commit is contained in:
58
src/main.ts
58
src/main.ts
@@ -1,22 +1,52 @@
|
||||
import Logging from "log-like-a-zombie";
|
||||
import express from "express";
|
||||
import Logging from "@proxnet/undead-logging";
|
||||
import * as Config from "./config.ts";
|
||||
import { Application, Router } from "@oak/oak";
|
||||
import { Redis } from "./db.ts";
|
||||
import { Discord } from "./discord.ts";
|
||||
import { APIUtils } from "./apiutils.ts";
|
||||
|
||||
const log = new Logging("Main");
|
||||
|
||||
const port = 3000;
|
||||
const address = "127.0.0.1";
|
||||
log.i(`Starting Galvanic Corrosion..`);
|
||||
|
||||
log.i(`Starting HTTP server on http://${address}:${port}`);
|
||||
const config = Config.getConfig();
|
||||
|
||||
const app = express();
|
||||
app.disable('etag');
|
||||
app.disable('x-powered-by');
|
||||
if (typeof config == 'undefined') {
|
||||
log.e('Cannot start: Configuration is undefined');
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
app.use((rq: express.Request, rs: express.Response) => {
|
||||
log.n(`${rq.ip} ${rq.method} ${rq.originalUrl}`);
|
||||
rs.sendStatus(200);
|
||||
});
|
||||
const port = config.web.port;
|
||||
const host = config.web.host;
|
||||
|
||||
app.listen(port, address, () => {
|
||||
log.i(`Listening on http://${address}:${port}`);
|
||||
log.i(`Starting HTTP server on http://${host}:${port}`);
|
||||
|
||||
const abortController = new AbortController();
|
||||
const app = new Application();
|
||||
|
||||
app.use(new Router().all('/', APIUtils.genericResponse(false, `${config?.public.serverName} - ${config?.public.motd}`)).routes());
|
||||
|
||||
try {
|
||||
log.i(`Connecting to Redis..`);
|
||||
Redis.connectToRedis();
|
||||
} catch (err) {
|
||||
log.e(`Cannot start: Redis could not be initialized. ${err}`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
app.listen({port: port, hostname: host, signal: abortController.signal });
|
||||
} 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();
|
||||
});
|
||||
Reference in New Issue
Block a user