This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/backend/server.coffee

41 lines
889 B
CoffeeScript
Raw Normal View History

2018-12-07 09:38:46 +00:00
# node libraries
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
app = express()
app.use helmet()
app.use bodyParser.urlencoded
extended: true
2018-12-15 20:09:01 +00:00
# sessions
sessionMiddleware = FFTCGSESSION(app)
2018-12-15 20:09:01 +00:00
app.use sessionMiddleware
# 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-12-07 09:38:46 +00:00
# Handle termination
process.on 'SIGINT', ->
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()