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/server.coffee

41 lines
908 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')
# 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
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
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-12-07 09:38:46 +00:00
# Handle termination
process.on 'SIGINT', ->
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()