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')
|
2019-02-07 16:03:20 +00:00
|
|
|
logger = (require 'logging').default 'FFTCG'
|
2018-12-07 09:38:46 +00:00
|
|
|
|
|
|
|
# my libraries
|
2019-02-07 16:03:20 +00:00
|
|
|
FFTCGSOCKET = (require './socket')
|
|
|
|
FFTCGSESSION = (require './session')
|
|
|
|
FFTCGROUTER = (require './router')
|
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-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
|
2019-02-07 16:03:20 +00:00
|
|
|
web.listen 3001, ->
|
|
|
|
logger.info 'Listening on port 3001 ...'
|
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()
|
2019-02-07 16:03:20 +00:00
|
|
|
logger.info 'shutting down after SIGINT'
|
2018-12-07 09:38:46 +00:00
|
|
|
process.exit()
|