2018-12-07 09:38:46 +00:00
|
|
|
# node libraries
|
2018-12-16 01:40:01 +00:00
|
|
|
bodyParser = (require 'body-parser')
|
2018-12-07 09:38:46 +00:00
|
|
|
express = (require 'express')
|
2018-12-15 20:09:01 +00:00
|
|
|
sharedSession = (require 'express-socket.io-session')
|
2018-12-07 09:38:46 +00:00
|
|
|
helmet = (require 'helmet')
|
|
|
|
http = (require 'http')
|
|
|
|
path = (require 'path')
|
|
|
|
|
|
|
|
# my libraries
|
2018-12-14 22:41:43 +00:00
|
|
|
FFTCGSOCKET = (require './inc/fftcgsocket')
|
2018-12-16 01:40:01 +00:00
|
|
|
FFTCGSESSION = (require './inc/fftcgsession')
|
2018-12-16 02:02:57 +00:00
|
|
|
FFTCGROUTER = (require './inc/fftcgrouter')
|
2018-12-14 06:03:03 +00:00
|
|
|
|
2018-12-15 20:09:01 +00:00
|
|
|
# express framework
|
2018-11-29 13:14:53 +00:00
|
|
|
app = express()
|
|
|
|
app.use helmet()
|
2018-12-16 01:40:01 +00:00
|
|
|
app.use bodyParser.urlencoded
|
|
|
|
extended: true
|
2018-11-29 13:14:53 +00:00
|
|
|
|
2018-12-15 20:09:01 +00:00
|
|
|
# sessions
|
2018-12-16 01:40:01 +00:00
|
|
|
sessionMiddleware = FFTCGSESSION(app)
|
2018-12-15 20:09:01 +00:00
|
|
|
app.use sessionMiddleware
|
|
|
|
|
2018-12-16 21:51:08 +00:00
|
|
|
# routes
|
2018-12-16 02:02:57 +00:00
|
|
|
app.use FFTCGROUTER
|
2018-12-15 20:09:01 +00:00
|
|
|
|
2018-11-29 13:47:18 +00:00
|
|
|
# Templates
|
|
|
|
app.set 'view engine', 'pug'
|
|
|
|
app.get '/:template.html', (req, res) ->
|
2018-12-16 21:51:08 +00:00
|
|
|
if req.session.user
|
|
|
|
console.log "[FFTCG] user is '#{req.session.user.login}'"
|
2018-11-29 13:47:18 +00:00
|
|
|
res.render (req.params.template + '.pug')
|
|
|
|
|
2018-12-16 02:02:57 +00:00
|
|
|
# socket.io
|
2018-12-14 22:41:43 +00:00
|
|
|
web = http.Server app
|
2018-12-16 02:02:57 +00:00
|
|
|
socket = new FFTCGSOCKET web, sharedSession sessionMiddleware
|
|
|
|
|
|
|
|
# Create server
|
2018-12-07 09:38:46 +00:00
|
|
|
web.listen 3000, ->
|
|
|
|
console.log '[FFTCG] Listening on port 3000 ...'
|
2018-11-29 13:14:53 +00:00
|
|
|
|
2018-12-07 09:38:46 +00:00
|
|
|
# Handle termination
|
|
|
|
process.on 'SIGINT', ->
|
2018-12-14 12:31:07 +00:00
|
|
|
socket.close()
|
2018-12-07 09:38:46 +00:00
|
|
|
console.log '[FFTCG] shutting down after SIGINT'
|
|
|
|
process.exit()
|