Make new frontend deployable.

* Get rid of old client and its grunt build.
* Make `yarn run dist` bundle a working version with new frontend.
* Make sure to handle history mode URLs on server side.
This commit is contained in:
baldo 2022-10-04 15:33:55 +02:00
commit e48c2861c6
810 changed files with 109 additions and 348223 deletions

View file

@ -7,11 +7,13 @@ import compress from "compression";
import express, { Express, NextFunction, Request, Response } from "express";
import { promises as fs } from "graceful-fs";
import * as apiRouter from "./router";
import { config } from "./config";
import type { CleartextPassword, PasswordHash, Username } from "./types";
import { isString } from "./types";
import Logger from "./logger";
import { HttpHeader, HttpStatusCode, MimeType } from "./shared/utils/http";
import history from "connect-history-api-fallback";
export const app: Express = express();
@ -95,8 +97,9 @@ export function init(): void {
router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: true }));
const adminDir = __dirname + "/../admin";
const clientDir = __dirname + "/../client";
// TODO: This is deprecated. Remove some time after re-launch. Used only for legacy clients that have not yet reloaded.
const templateDir = __dirname + "/templates";
const jsTemplateFiles = ["/config.js"];
@ -133,8 +136,21 @@ export function init(): void {
}
});
router.use("/internal/admin", express.static(adminDir + "/"));
router.use("/", express.static(clientDir + "/"));
app.use(config.server.rootPath, router);
apiRouter.init();
// Handle URLs not found before to be compatible with history mode.
const historyLogger = Logger.tag("history-api-fallback");
app.use(
history({
index: "/index.html",
logger: historyLogger.debug.bind(historyLogger),
})
);
// Re-serve static content after rewrite by history mode fallback.
app.use(config.server.rootPath, router);
}

View file

@ -3,7 +3,6 @@ import { config } from "./config";
import Logger from "./logger";
import * as db from "./db/database";
import * as scheduler from "./jobs/scheduler";
import * as router from "./router";
import * as app from "./app";
import * as mail from "./mail";
@ -17,7 +16,6 @@ async function main() {
await db.init();
mail.init();
scheduler.init();
router.init();
app.app.listen(config.server.port, "::");
}

View file

@ -1,3 +1,4 @@
// TODO: This is deprecated. Remove some time after re-launch. Used only for legacy clients that have not yet reloaded.
'use strict';
angular.module('ffffng').constant('config', <%= JSON.stringify(config) %>);