lolisafe.js 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. const config = require('./config.js')
  2. const api = require('./routes/api.js')
  3. const express = require('express')
  4. const bodyParser = require('body-parser')
  5. const db = require('knex')(config.database)
  6. const fs = require('fs')
  7. const safe = express()
  8. require('./database/db.js')(db)
  9. fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder)
  10. fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder)
  11. fs.existsSync('./' + config.uploads.folder + '/thumbs') || fs.mkdirSync('./' + config.uploads.folder + '/thumbs')
  12. safe.use(bodyParser.urlencoded({ extended: true }))
  13. safe.use(bodyParser.json())
  14. safe.enable('trust proxy')
  15. safe.use('/', express.static('./uploads'))
  16. safe.use('/', express.static('./public'))
  17. safe.use('/api', api)
  18. safe.get('/', (req, res, next) => res.sendFile('home.html', { root: './pages/' }))
  19. safe.get('/faq', (req, res, next) => res.sendFile('faq.html', { root: './pages/' }))
  20. safe.get('/auth', (req, res, next) => res.sendFile('auth.html', { root: './pages/' }))
  21. safe.get('/dashboard', (req, res, next) => res.sendFile('dashboard.html', { root: './pages/' }))
  22. safe.use((req, res, next) => res.status(404).sendFile('404.html', { root: './pages/error/' }))
  23. safe.use((req, res, next) => res.status(500).sendFile('500.html', { root: './pages/error/' }))
  24. safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))