Reorganised some routing logic. Added separate views for SPAs and reorganised static folders to be globally accessible, so that the separate views can access the right folder. Language can be permanently changed for account.

This commit is contained in:
Daniel Ledda
2020-05-24 11:33:25 +02:00
parent 83844588df
commit 3a7e7de3d4
17 changed files with 1447 additions and 3537 deletions

View File

@@ -1,23 +1,25 @@
import express from "express";
import {requireAuthenticated, requireNotAuthenticated} from "../passport-config";
import {requireAuthenticated} from "../passport-config";
import routers from "./routers";
import {IDbUser} from "../models/dbUser";
import * as path from "path";
const router = express.Router();
router.use("/account", routers.signup);
router.use("/api", routers.api);
router.use("/game/static", express.static(path.join(__dirname, "../game/static")));
router.use("/static", express.static(path.join(__dirname, "../frontend/static")));
router.use("/static", express.static("static"));
// General Endpoints
router.get("/game", requireAuthenticated, (req, res) => {
res.sendFile(path.join(__dirname + "/../game/index.html"));
res.render("gameIndex.ejs", {
username: (req.user as IDbUser).username,
rootUrl: req.app.locals.rootUrl
});
});
router.get("", requireAuthenticated, (req, res) => {
res.sendFile(path.join(__dirname + "/../frontend/index.html"), {username: (req.user as IDbUser).username});
router.get("/**", requireAuthenticated, (req, res) => {
res.render("frontendIndex.ejs", {
username: (req.user as IDbUser).username,
rootUrl: req.app.locals.rootUrl
});
});
export default router;