lolisafe.js 978 B

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