2017-01-13 07:34:21 +00:00
|
|
|
const config = require('./config.js')
|
2017-01-15 01:36:24 +00:00
|
|
|
const api = require('./routes/api.js')
|
2017-01-14 08:50:18 +00:00
|
|
|
const routes = require('./routes/routes.js')
|
2017-01-13 07:34:21 +00:00
|
|
|
const express = require('express')
|
|
|
|
const db = require('knex')(config.database)
|
|
|
|
const fs = require('fs')
|
|
|
|
const safe = express()
|
|
|
|
|
2017-01-14 08:50:18 +00:00
|
|
|
require('./database/db.js')(db)
|
|
|
|
|
2017-01-13 07:34:21 +00:00
|
|
|
fs.existsSync('./' + config.uploads.folder) || fs.mkdirSync('./' + config.uploads.folder)
|
|
|
|
fs.existsSync('./' + config.logsFolder) || fs.mkdirSync('./' + config.logsFolder)
|
|
|
|
|
2017-01-14 06:01:23 +00:00
|
|
|
safe.enable('trust proxy')
|
|
|
|
|
2017-01-14 08:50:18 +00:00
|
|
|
let prefix = config.uploads.prefix
|
|
|
|
if( prefix !== '' )
|
|
|
|
prefix = prefix + '/'
|
|
|
|
|
|
|
|
safe.use('/' + prefix, express.static('./uploads'))
|
2017-01-14 06:01:23 +00:00
|
|
|
safe.use('/', express.static('./public'))
|
2017-01-15 01:36:24 +00:00
|
|
|
safe.use('/', routes)
|
|
|
|
safe.use('/api', api)
|
2017-01-14 06:01:23 +00:00
|
|
|
|
|
|
|
safe.use(function (req, res, next) {
|
|
|
|
res.status(404).sendFile('404.html', {
|
|
|
|
root: './public/error/',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
safe.use(function (err, req, res, next) {
|
|
|
|
res.status(500).end()
|
|
|
|
})
|
2017-01-13 07:34:21 +00:00
|
|
|
|
2017-01-14 21:13:58 +00:00
|
|
|
safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))
|
|
|
|
|
|
|
|
if(config.TOKEN !== '') console.log('Use the following token as the \'auth\' header in your requests to the API: ' + config.TOKEN)
|
|
|
|
else console.log('Running lolisafe in public mode. No token required.')
|