46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
import { Server } from "rjweb-server";
|
|
import { Runtime } from "@rjweb/runtime-node";
|
|
import * as dotenv from "dotenv";
|
|
import * as mongoDB from "mongodb";
|
|
import { env } from "node:process";
|
|
|
|
dotenv.config({ path: "../.env" });
|
|
|
|
export const config = {
|
|
CookieDomain: env.COOKIE_DOMAIN || "localhost"
|
|
}
|
|
|
|
const client: mongoDB.MongoClient = new mongoDB.MongoClient(
|
|
env.DB_CONN_STRING!
|
|
);
|
|
|
|
const db: mongoDB.Db = client.db("exams_db");
|
|
|
|
const COOKIENAME = "exams_session";
|
|
export { db, client, COOKIENAME };
|
|
|
|
const server = new Server(Runtime, {
|
|
port: 8080,
|
|
});
|
|
|
|
export const fileRouter = new server.FileLoader("/")
|
|
.load("./routes", { fileBasedRouting: false })
|
|
.export();
|
|
|
|
server.path("/", (path) =>
|
|
path.static("../../frontend/dist", {
|
|
stripHtmlEnding: true,
|
|
})
|
|
);
|
|
|
|
server.notFound(async (ctr) => {
|
|
return ctr
|
|
.status(200, "maybe frontend?")
|
|
.printFile("../../frontend/dist/index.html", { addTypes: true });
|
|
});
|
|
|
|
server.start().then(async (port) => {
|
|
await client.connect();
|
|
|
|
console.log(`Server started on port ${port}!`);
|
|
}); |