-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathserver.js
More file actions
64 lines (57 loc) · 1.97 KB
/
server.js
File metadata and controls
64 lines (57 loc) · 1.97 KB
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
require('dotenv').config()
const express = require('express')
const app = express()
const http = require('http')
const SocketsServer = require('socket.io')
const ANALYTICS = require('stats-not-tracks')
const utils = require('./my_modules/utils.js')
const ROUTES = require('./my_modules/routes.js')
const GITHUB = require('./my_modules/github.js')
const SOCKETS = require('./my_modules/sockets.js')
const ERRORS = require('./my_modules/errors.js')
const PORT = process.env.PORT || 8001
const fs = require('fs')
const path = require('path')
const cookieParser = require('cookie-parser')
app.use(cookieParser())
app.use(express.json({ limit: '50mb' })) // GitHub's limit is 100mb
// our /etc/nginx/sites-available/default should also reflect this:
// client_max_body_size 50M;
ANALYTICS.setup(app, {
path: `${__dirname}/data/analytics`,
admin: {
route: 'analytics',
dashboard: `${__dirname}/data/analytics`,
secret: process.env.ANALYTICS_SECRET,
hash: process.env.ANALYTICS_HASH
}
})
if (process.env.CURTAIN) {
app.get('/', (req, res) => {
const curtain = fs.readFileSync(path.join(__dirname, 'www', 'curtain.html'), 'utf8')
res.send(curtain.replace('{{MESSAGE}}', process.env.CURTAIN))
})
}
app.use('/api', utils.corsGate)
app.use(ROUTES)
app.use(GITHUB)
app.use(express.static(`${__dirname}/www`))
app.use('/docs', express.static(`${__dirname}/docs`))
app.use(ERRORS.notFound)
app.use(ERRORS.errorHandler)
const io = new SocketsServer.Server()
io.on('connection', (socket) => SOCKETS(socket, io))
const httpServer = http.createServer(app)
const msg = `
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/ '.
| hi there! the local server is up and |
| running, open a browser and visit: |
| http://localhost:${PORT} |
\` _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ,/
.'\`
( ◕ ◞ ◕ )つ
`
httpServer.listen(PORT, () => console.log(msg))
io.attach(httpServer)
ANALYTICS.live(httpServer, io)