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-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-16 07:37:42 +00:00
|
|
|
require('./database/db.js')(db, config)
|
2017-01-14 08:50:18 +00:00
|
|
|
|
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('/api', api)
|
2017-01-14 06:01:23 +00:00
|
|
|
|
2017-01-17 18:55:27 +00:00
|
|
|
safe.get('/', function (req, res, next) {
|
|
|
|
res.sendFile('home.html', {
|
|
|
|
root: './pages/'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
safe.get('/panel', function (req, res, next) {
|
|
|
|
res.sendFile('panel.html', {
|
|
|
|
root: './pages/'
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-01-14 06:01:23 +00:00
|
|
|
safe.use(function (req, res, next) {
|
|
|
|
res.status(404).sendFile('404.html', {
|
2017-01-17 18:55:27 +00:00
|
|
|
root: './pages/error/',
|
2017-01-14 06:01:23 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
safe.use(function (err, req, res, next) {
|
2017-01-17 18:56:44 +00:00
|
|
|
res.status(500).sendFile('500.html', {
|
|
|
|
root: './pages/error/',
|
|
|
|
})
|
2017-01-14 06:01:23 +00:00
|
|
|
})
|
2017-01-13 07:34:21 +00:00
|
|
|
|
2017-01-16 07:37:42 +00:00
|
|
|
safe.listen(config.port, () => console.log(`loli-safe started on port ${config.port}`))
|