lolisafe.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const config = require('./config.js')
  2. const routes = require('./routes.js')
  3. const express = require('express')
  4. const db = require('knex')(config.database)
  5. const fs = require('fs')
  6. const safe = express()
  7. fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder)
  8. fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder)
  9. fs.existsSync('db') || fs.writeFile('db', '')
  10. safe.enable('trust proxy')
  11. safe.use('/', express.static('./uploads'))
  12. safe.use('/', express.static('./public'))
  13. safe.use('/api' , routes)
  14. safe.use(function (req, res, next) {
  15. res.status(404).sendFile('404.html', {
  16. root: './public/error/',
  17. })
  18. })
  19. safe.use(function (err, req, res, next) {
  20. res.status(500).end()
  21. })
  22. // Create the tables we need to store galleries and files
  23. db.schema.createTableIfNotExists('gallery', function (table) {
  24. table.increments()
  25. table.string('name')
  26. table.timestamps()
  27. }).then(() => {})
  28. db.schema.createTableIfNotExists('files', function (table) {
  29. table.increments()
  30. table.string('file')
  31. table.integer('galleryid')
  32. }).then(() => {})
  33. safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))