Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move static pages to reduce clutter in the express.js #474

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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