lolisafe.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. const config = require('./config.js')
  2. const api = require('./routes/api.js')
  3. const express = require('express')
  4. const db = require('knex')(config.database)
  5. const fs = require('fs')
  6. const safe = express()
  7. require('./database/db.js')(db, config)
  8. fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder)
  9. fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder)
  10. safe.enable('trust proxy')
  11. let prefix = config.uploads.prefix
  12. if( prefix !== '' )
  13. prefix = prefix + '/'
  14. safe.use('/' + prefix, express.static('./uploads'))
  15. safe.use('/', express.static('./public'))
  16. safe.use('/api', api)
  17. safe.get('/', (req, res, next) => res.sendFile('home.html', { root: './pages/' }))
  18. safe.get('/panel', (req, res, next) => res.sendFile('panel.html', { root: './pages/' }))
  19. safe.use((req, res, next) => res.status(404).sendFile('404.html', { root: './pages/error/' }))
  20. safe.use((req, res, next) => res.status(500).sendFile('500.html', { root: './pages/error/' }))
  21. safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))