38 lines
1008 B
JavaScript
38 lines
1008 B
JavaScript
const express = require('express')
|
|
const app = express()
|
|
const fs = require('fs')
|
|
const util = require('./server/util')
|
|
require('dotenv').config()
|
|
|
|
app.set('env', process.env.NODE_ENV || "production")
|
|
app.set('view engine', 'pug')
|
|
app.set('port', process.env.PORT || 3000)
|
|
app.set('db_path', process.env.DB_PATH || "/data")
|
|
|
|
if (!fs.existsSync(app.get('db_path'))) {
|
|
fs.mkdirSync(app.get('db_path'))
|
|
}
|
|
const db_path_file = path.join(app.get('db_path'), 'db.json')
|
|
if (!fs.existsSync(db_path_file)) {
|
|
fs.closeSync(fs.openSync(db_path_file, 'w'));
|
|
}
|
|
const adapter = new FileSync(db_path_file)
|
|
const db = low(adapter)
|
|
db.defaults({ posts: [] })
|
|
.write()
|
|
|
|
app.use((req, res, next) => {
|
|
req.db = db
|
|
})
|
|
|
|
app.use('/', require('./routes/main'))
|
|
app.use('/', require('./routes/static'))
|
|
app.use('/feed', require('./routes/feed'))
|
|
app.use('/rss', require('./routes/feed'))
|
|
|
|
util.updateDB()
|
|
|
|
app.listen(app.get('port'), () => {
|
|
console.log(`Node server listening at http://localhost:${app.get('port')}`)
|
|
})
|