From 86e903dc6715a46097e1a628ab15dab568591e82 Mon Sep 17 00:00:00 2001 From: 121593 <44259105+121593@users.noreply.github.com> Date: Fri, 13 Mar 2020 19:09:16 +0100 Subject: [PATCH] feat(): Adds a way to display content from GitHub to the website It allows to have some pages that will mirror content stored on openfab's repository cf #22 --- package.json | 1 + src/authentication/index.js | 1 + src/controllers/md.js | 20 ++++++++++++++++++++ src/server.js | 3 +++ src/views/md.ejs | 26 ++++++++++++++++++++++++++ 5 files changed, 51 insertions(+) create mode 100644 src/controllers/md.js create mode 100644 src/views/md.ejs diff --git a/package.json b/package.json index ec7b065..6825682 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "express": "4.16.2", "lodash": "4.17.15", "mailgun-js": "0.21.0", + "md-mirror": "^1.0.0", "node-sass-middleware": "0.11.0", "passport": "0.4.0", "pg": "7.4.1", diff --git a/src/authentication/index.js b/src/authentication/index.js index a247428..edab561 100755 --- a/src/authentication/index.js +++ b/src/authentication/index.js @@ -12,6 +12,7 @@ const publicRoutes = { '/contact': ['GET', 'POST'], '/membres': ['GET'], '/healthcheck': ['GET'], + '/md': ['GET'], '/inscription': ['GET', 'POST'] }; diff --git a/src/controllers/md.js b/src/controllers/md.js new file mode 100644 index 0000000..4ea6e68 --- /dev/null +++ b/src/controllers/md.js @@ -0,0 +1,20 @@ +const mdMirror = require('md-mirror') + +module.exports = (req, res) => { + + const mm = new mdMirror({ + baseLocalUrl: '/md', + baseRemoteUrl: 'https://raw.githubusercontent.com/openfab-lab', + viewManager: (content) => { + // While caching is not available set pages to be cached 24h + res.setHeader('Cache-Control', 'public, max-age=' + (60*60*24)); + res.render('../src/views/md.ejs', { + content, + user: req.user + }) + } + }) + + return mm.render(req.url) +} + diff --git a/src/server.js b/src/server.js index 63e5477..8d69fac 100644 --- a/src/server.js +++ b/src/server.js @@ -10,6 +10,8 @@ const sassMiddleware = require('node-sass-middleware'); const autoroute = require('./libs/autoroute'); const applyAuthentication = require('./authentication'); +const mdDisplay = require('./controllers/md') + const log = require('saga-logger').create({ module: module.id }); @@ -63,6 +65,7 @@ module.exports = () => { applyAuthentication(app); app.use('/', router); + app.get('/md/*', mdDisplay); app.all('*', (req, res, next) => { next(new ManagedError('API_GENERAL', 404)); diff --git a/src/views/md.ejs b/src/views/md.ejs new file mode 100644 index 0000000..e33e503 --- /dev/null +++ b/src/views/md.ejs @@ -0,0 +1,26 @@ +<%- include('./layout/top', {page: 'membre'}); %> + + + +