Skip to content

Commit

Permalink
move static pages to reduce clutter in the express
Browse files Browse the repository at this point in the history
  • Loading branch information
fcaps authored and Brutus5000 committed Nov 19, 2023
1 parent f94dbfd commit 8c5de75
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
29 changes: 2 additions & 27 deletions express.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const fs = require('fs');
const middleware = require('./routes/middleware');
const app = express();
const newsRouter = require('./routes/views/news');
const staticMarkdownRouter = require('./routes/views/staticMarkdownRouter');
const authRouter = require('./routes/views/auth');

app.locals.clanInvitations = {};
Expand Down Expand Up @@ -70,14 +71,8 @@ function loggedIn(req, res, next) {
}
}

//Start and listen on port



// --- R O U T E S ---
// when the website is asked to render "/pageName" it will come here and see what are the "instructions" to render said page. If the page isn't here, then the website won't render it properly.

app.use('/news', newsRouter)
app.use('/', staticMarkdownRouter)
app.use('/', authRouter)

// --- UNPROTECTED ROUTES ---
Expand Down Expand Up @@ -150,26 +145,6 @@ clansRoutesPost.forEach(page => app.post(`/clans/${page}`, loggedIn, (req, res)
app.get('/clans/*', (req, res) => res.status(503).render('errors/503-known-issue'));


// Markdown Routes

// ToS and Privacy Statement
function markdown(template) {
let html = new showdown.Converter().makeHtml(fs.readFileSync(template, 'utf-8'));
return (req, res) => {
res.render('markdown', {content: html});
};
}

app.get('/privacy', markdown('templates/views/markdown/privacy.md'));
app.get('/privacy-fr', markdown('templates/views/markdown/privacy-fr.md'));
app.get('/privacy-ru', markdown('templates/views/markdown/privacy-ru.md'));
app.get('/tos', markdown('templates/views/markdown/tos.md'));
app.get('/tos-fr', markdown('templates/views/markdown/tos-fr.md'));
app.get('/tos-ru', markdown('templates/views/markdown/tos-ru.md'));
app.get('/rules', markdown('templates/views/markdown/rules.md'));
app.get('/cg', markdown('templates/views/markdown/cg.md'));


// ---ODD BALLS---
// Routes that might not be able to be added into the loops due to their nature in naming
/* Removed
Expand Down
23 changes: 23 additions & 0 deletions routes/views/staticMarkdownRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const express = require('express')
const showdown = require('showdown')
const fs = require('fs')
const router = express.Router()

function markdown(template) {
return (req, res) => {
res.render('markdown', {
content: new showdown.Converter().makeHtml(fs.readFileSync(template, 'utf-8'))
})
}
}

router.get('/privacy', markdown('templates/views/markdown/privacy.md'))
router.get('/privacy-fr', markdown('templates/views/markdown/privacy-fr.md'))
router.get('/privacy-ru', markdown('templates/views/markdown/privacy-ru.md'))
router.get('/tos', markdown('templates/views/markdown/tos.md'))
router.get('/tos-fr', markdown('templates/views/markdown/tos-fr.md'))
router.get('/tos-ru', markdown('templates/views/markdown/tos-ru.md'))
router.get('/rules', markdown('templates/views/markdown/rules.md'))
router.get('/cg', markdown('templates/views/markdown/cg.md'))

module.exports = router

0 comments on commit 8c5de75

Please sign in to comment.