lolisafe.js 1.3 KB

123456789101112131415161718192021222324252627282930
  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('/auth', (req, res, next) => res.sendFile('auth.html', { root: './pages/' }))
  20. safe.get('/panel', (req, res, next) => res.sendFile('panel.html', { root: './pages/' }))
  21. safe.use((req, res, next) => res.status(404).sendFile('404.html', { root: './pages/error/' }))
  22. safe.use((req, res, next) => res.status(500).sendFile('500.html', { root: './pages/error/' }))
  23. safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))