forked from worknenjoy/gitpay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
68 lines (55 loc) · 1.75 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require('express')
const cors = require('cors')
const sslRedirect = require('heroku-ssl-redirect')
const app = express()
const session = require('express-session')
const compression = require('compression')
const bodyParser = require('body-parser')
require('./models')
const passport = require('passport')
require('./config/passport')
const load = require('./modules/app')
const feed = require('feed-read')
const i18n = require('i18n')
const { dailyJob, weeklyJob, weeklyJobLatest } = require('./cron')
if (process.env.NODE_ENV !== 'production') {
app.use(cors())
}
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(session({
secret: process.env.SECRET_PHRASE,
saveUninitialized: true,
resave: true
}))
i18n.configure({
directory: process.env.NODE_ENV !== 'production' ? `${__dirname}/locales` : `${__dirname}/locales/result`,
locales: process.env.NODE_ENV !== 'production' ? ['en'] : ['en', 'br'],
defaultLocale: 'en',
updateFiles: false
})
app.use(i18n.init)
dailyJob.start()
weeklyJob.start()
weeklyJobLatest.start()
app.use(passport.initialize())
app.use(passport.session())
app.use(sslRedirect())
app.set('port', (process.env.PORT || 3000))
app.use(compression())
app.use(express.static(`${__dirname}/frontend/public/`))
app.get('/octos', (req, res) => {
feed('http://feeds.feedburner.com/Octocats', (err, articles) => {
if (err) throw err
const article = articles[Math.floor(Math.random() * articles.length)]
// eslint-disable-next-line no-console
console.log(article)
return res.json(article).end()
})
})
load.init(app)
app.listen(app.get('port'), () => {
// eslint-disable-next-line no-console
console.log('Node app is running on port', app.get('port'))
})
module.exports = app