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-27 11:19:19 +00:00
|
|
|
FFTCGSOCKET = (require './inc/socket')
|
|
|
|
FFTCGSESSION = (require './inc/session')
|
|
|
|
FFTCGROUTER = (require './inc/router')
|
2018-12-27 12:03:58 +00:00
|
|
|
FFTCGLOG = new (require './inc/console')('FFTCG')
|
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
|
2018-12-07 09:38:46 +00:00
|
|
|
web.listen 3000, ->
|
2018-12-27 12:03:58 +00:00
|
|
|
FFTCGLOG.log '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-27 12:03:58 +00:00
|
|
|
FFTCGLOG.log 'shutting down after SIGINT'
|
2018-12-07 09:38:46 +00:00
|
|
|
process.exit()
|