User stuff, config structure changes, web panel start, versioncheck fix, api start, recaptcha support for web panel
This commit is contained in:
20
src/main.ts
20
src/main.ts
@@ -2,8 +2,10 @@ import * as Log from "@proxnet/undead-logging";
|
||||
import * as Config from "./config.ts";
|
||||
// @ts-types = 'npm:@types/express'
|
||||
import express from "express";
|
||||
import { Redis } from "./db.ts";
|
||||
import { Database } from "./db.ts";
|
||||
import { APIUtils } from "./apiutils.ts";
|
||||
import { Discord } from "./discord.ts";
|
||||
import { User } from "./data/users.ts";
|
||||
|
||||
const log = new Log.default("Main");
|
||||
|
||||
@@ -39,14 +41,23 @@ app.use((rq: express.Request, rs: express.Response, nxt: express.NextFunction) =
|
||||
nxt();
|
||||
});
|
||||
|
||||
app.use('/', APIUtils.genericResponse(false, `${config?.public.serverName} - ${config?.public.motd}`));
|
||||
app.get('/', APIUtils.genericResponse(false, `${config?.public.serverName} - ${config?.public.motd}`));
|
||||
|
||||
app.get('/debug', async (_rq, rs) => {
|
||||
const user = await User.init({ username: "testuser123", password: "foopass123" });
|
||||
log.i(String(user == null));
|
||||
|
||||
rs.sendStatus(200);
|
||||
});
|
||||
|
||||
// content routes
|
||||
const nameserverRouter = await import('./routes/nameserver.ts');
|
||||
const apiRouter = await import('./routes/api.ts');
|
||||
const userRouter = await import('./routes/user.ts');
|
||||
|
||||
app.use(nameserverRouter.route.path, nameserverRouter.route.router);
|
||||
app.use(apiRouter.route.path, apiRouter.route.router);
|
||||
app.use(userRouter.route.path, userRouter.route.router);
|
||||
|
||||
app.use((rq: express.Request, rs: express.Response) => {
|
||||
log.e(`${APIUtils.getSrcIpDefault(rq)} 404 ${rq.method} ${rq.url.toString()}`);
|
||||
@@ -55,8 +66,7 @@ app.use((rq: express.Request, rs: express.Response) => {
|
||||
});
|
||||
|
||||
try {
|
||||
log.i(`Connecting to Redis..`);
|
||||
Redis.connectToRedis();
|
||||
Database.connect();
|
||||
} catch (err) {
|
||||
log.e(`Cannot start: Redis could not be initialized. ${err}`);
|
||||
Deno.exit(1);
|
||||
@@ -81,4 +91,4 @@ try {
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
//Discord.login(); do not use for now
|
||||
Discord.login();
|
||||
Reference in New Issue
Block a user