Skip to content

Commit

Permalink
Merge pull request #417 from dyc3/misc-server-updates
Browse files Browse the repository at this point in the history
misc server updates
  • Loading branch information
dyc3 authored May 12, 2021
2 parents 228b8e9 + cd10a4f commit 6508b2e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 39 deletions.
25 changes: 13 additions & 12 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ function checkRedis() {
}
checkRedis();

if (fs.existsSync("./dist")) {
// serve static files without creating a bunch of sessions
app.use(express.static(__dirname + "/dist", {
maxAge: "2 days",
redirect: false,
index: false,
}));
}
else {
log.warn("no dist folder found");
}

const session = require('express-session');
let RedisStore = require('connect-redis')(session);
let sessionOpts = {
Expand Down Expand Up @@ -172,11 +184,6 @@ app.use(bodyParser.urlencoded({ // to support URL-encoded bodies
extended: true,
}));

// Redirect urls with trailing slashes
app.get('\\S+/$', (req, res) => {
return res.redirect(301, req.path.slice(0, -1) + req.url.slice(req.path.length));
});

app.use((req, res, next) => {
if (!req.path.startsWith("/api")) {
next();
Expand All @@ -201,13 +208,7 @@ function serveBuiltFiles(req, res) {
app.use("/api/user", usermanager.router);
app.use("/api", api);
if (fs.existsSync("./dist")) {
app.use(express.static(__dirname + "/dist", false));
app.get("/", serveBuiltFiles);
app.get("/faq", serveBuiltFiles);
app.get("/rooms", serveBuiltFiles);
app.get("/room/:roomId", serveBuiltFiles);
app.get("/privacypolicy", serveBuiltFiles);
app.get("/quickroom", serveBuiltFiles);
app.get("*", serveBuiltFiles);
}
else {
log.warn("no dist folder found");
Expand Down
30 changes: 3 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6508b2e

Please sign in to comment.