Преглед на файлове

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.
Pitu преди 7 години
родител
ревизия
18c66d27fb
променени са 3 файла, в които са добавени 23 реда и са изтрити 6 реда
  1. 3 1
      .gitignore
  2. 3 0
      config.sample.js
  3. 17 5
      lolisafe.js

+ 3 - 1
.gitignore

@@ -1,8 +1,10 @@
 .DS_Store
+!.gitkeep
 node_modules/
 uploads/
 logs/
 database/db
 config.js
 start.json
-npm-debug.log
+npm-debug.log
+pages/custom/**

+ 3 - 0
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: {
 

+ 17 - 5
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}`))
+safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))
+
+safe.prepareFrontendRoutes = function(){
+
+	
+
+}