ecc340e7b1
Dark mode: CSS custom properties + .dark class toggled via Redux/localStorage, with a theme toggle in the Header and Settings page. Foundation didn't exist yet despite prior assumption, so it was built from scratch. SQLite: new DB_ENGINE=mongo|sqlite env var selects the metadata backend at runtime (Mongo stays default, no behavior change unless opted in). File/thumbnail bytes continue to use the existing fs/S3 storage path. Implemented via a shared DB interface (dbTypes.ts) with parallel mongoDB/ and sqliteDB/ implementations, selected through dbFactory.ts, with JWT/encryption logic extracted into userCrypto.ts so both engines share it.
87 lines
2.2 KiB
TypeScript
Executable File
87 lines
2.2 KiB
TypeScript
Executable File
import express, { Request, Response } from "express";
|
|
import path from "path";
|
|
import userRouter from "../express-routers/user-router";
|
|
import fileRouter from "../express-routers/file-router";
|
|
import folderRouter from "../express-routers/folder-router";
|
|
import bodyParser from "body-parser";
|
|
import https from "https";
|
|
import fs from "fs";
|
|
import helmet from "helmet";
|
|
import busboy from "connect-busboy";
|
|
import compression from "compression";
|
|
import http from "http";
|
|
import cookieParser from "cookie-parser";
|
|
import env from "../enviroment/env";
|
|
import { middlewareErrorHandler } from "../middleware/utils/middleware-utils";
|
|
import cors from "cors";
|
|
// import requestIp from "request-ip";
|
|
|
|
const app = express();
|
|
const publicPath = path.join(__dirname, "..", "..", "dist-frontend");
|
|
|
|
let server: any;
|
|
let serverHttps: any;
|
|
|
|
if (process.env.SSL === "true") {
|
|
const certPath = env.httpsCrtPath || "certificate.crt"
|
|
const caPath = env.httpsCaPath || "certificate.ca-bundle"
|
|
const keyPath = env.httpsKeyPath || "certificate.key"
|
|
const cert = fs.readFileSync(certPath);
|
|
const ca = fs.readFileSync(caPath);
|
|
const key = fs.readFileSync(keyPath);
|
|
|
|
const options = {
|
|
cert,
|
|
ca,
|
|
key,
|
|
};
|
|
|
|
serverHttps = https.createServer(options, app);
|
|
}
|
|
|
|
server = http.createServer(app);
|
|
|
|
if (env.dbEngine === "sqlite") {
|
|
require("../db/connections/sqlite");
|
|
} else {
|
|
require("../db/connections/mongoose");
|
|
}
|
|
|
|
app.use(cors());
|
|
app.use(cookieParser(env.passwordCookie));
|
|
app.use(helmet());
|
|
app.use(compression());
|
|
app.use(express.json());
|
|
app.use(express.static(publicPath, { index: false }));
|
|
app.use(bodyParser.json({ limit: "50mb" }));
|
|
app.use(
|
|
bodyParser.urlencoded({
|
|
limit: "50mb",
|
|
extended: true,
|
|
parameterLimit: 50000,
|
|
})
|
|
);
|
|
// app.use(requestIp.mw());
|
|
|
|
app.use(
|
|
busboy({
|
|
highWaterMark: 2 * 1024 * 1024,
|
|
})
|
|
);
|
|
|
|
app.use(userRouter, fileRouter, folderRouter);
|
|
|
|
app.use(middlewareErrorHandler);
|
|
|
|
//const nodeMode = process.env.NODE_ENV ? "Production" : "Development/Testing";
|
|
|
|
//console.log("Node Enviroment Mode:", nodeMode);
|
|
|
|
if (process.env.NODE_ENV === "production") {
|
|
app.get("*", (_: Request, res: Response) => {
|
|
res.sendFile(path.join(publicPath, "index.html"));
|
|
});
|
|
}
|
|
|
|
export default { server, serverHttps };
|