From 8c5de75efcd7288173c605b8d02efb18174ad15d Mon Sep 17 00:00:00 2001 From: fcaps Date: Sun, 19 Nov 2023 05:15:59 +0100 Subject: [PATCH] move static pages to reduce clutter in the express --- express.js | 29 ++-------------------------- routes/views/staticMarkdownRouter.js | 23 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 routes/views/staticMarkdownRouter.js diff --git a/express.js b/express.js index 8e83154c..1eb3bfc6 100644 --- a/express.js +++ b/express.js @@ -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 = {}; @@ -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 --- @@ -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 diff --git a/routes/views/staticMarkdownRouter.js b/routes/views/staticMarkdownRouter.js new file mode 100644 index 00000000..6b8c9e5c --- /dev/null +++ b/routes/views/staticMarkdownRouter.js @@ -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