From 18c66d27fb580ed0f847f11525d2d2dca0fda2f4 Mon Sep 17 00:00:00 2001 From: Pitu Date: Mon, 6 Feb 2017 00:06:33 -0300 Subject: [PATCH] Added support for custom html files There's a new folder that gets created upon running lolisafe for the first time. On said folder any html file with the same name as the default ones will be loaded instead, letting you place custom frontend files without messing with git. --- .gitignore | 4 +++- config.sample.js | 3 +++ lolisafe.js | 22 +++++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index ac8e2b3..b806686 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,10 @@ .DS_Store +!.gitkeep node_modules/ uploads/ logs/ database/db config.js start.json -npm-debug.log \ No newline at end of file +npm-debug.log +pages/custom/** \ No newline at end of file diff --git a/config.sample.js b/config.sample.js index 7c881d9..400bc72 100644 --- a/config.sample.js +++ b/config.sample.js @@ -31,6 +31,9 @@ module.exports = { // Port on which to run the server port: 9999, + // Pages to process for the frontend + pages: ['home', 'auth', 'dashboard', 'faq'], + // Uploads config uploads: { diff --git a/lolisafe.js b/lolisafe.js index 52d0c4f..dc749ee 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -9,6 +9,7 @@ const safe = express() require('./database/db.js')(db) +fs.existsSync('./pages/custom' ) || fs.mkdirSync('./pages/custom') fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder) fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder) fs.existsSync('./' + config.uploads.folder + '/thumbs') || fs.mkdirSync('./' + config.uploads.folder + '/thumbs') @@ -26,11 +27,22 @@ safe.use('/', express.static('./uploads')) safe.use('/', express.static('./public')) safe.use('/api', api) -safe.get('/', (req, res, next) => res.sendFile('home.html', { root: './pages/' })) -safe.get('/faq', (req, res, next) => res.sendFile('faq.html', { root: './pages/' })) -safe.get('/auth', (req, res, next) => res.sendFile('auth.html', { root: './pages/' })) -safe.get('/dashboard', (req, res, next) => res.sendFile('dashboard.html', { root: './pages/' })) +for(let page of config.pages){ + let root = './pages/' + if(fs.existsSync(`./pages/custom/${page}.html`)) + root = './pages/custom/' + + if(page === 'home') safe.get('/', (req, res, next) => res.sendFile(`${page}.html`, { root: root })) + else safe.get(`/${page}`, (req, res, next) => res.sendFile(`${page}.html`, { root: root })) +} + safe.use((req, res, next) => res.status(404).sendFile('404.html', { root: './pages/error/' })) safe.use((req, res, next) => res.status(500).sendFile('500.html', { root: './pages/error/' })) -safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`)) \ No newline at end of file +safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`)) + +safe.prepareFrontendRoutes = function(){ + + + +} \ No newline at end of file