# node libraries bodyParser = (require 'body-parser') express = (require 'express') sharedSession = (require 'express-socket.io-session') helmet = (require 'helmet') http = (require 'http') path = (require 'path') # my libraries FFTCGSOCKET = (require './inc/fftcgsocket') FFTCGSESSION = (require './inc/fftcgsession') FFTCGROUTER = (require './inc/fftcgrouter') # express framework app = express() app.use helmet() app.use bodyParser.urlencoded extended: true # sessions sessionMiddleware = FFTCGSESSION(app) app.use sessionMiddleware # REST routes app.use FFTCGROUTER # Static content app.use express.static path.resolve(__dirname, 'public_html') # Templates app.set 'view engine', 'pug' app.get '/:template.html', (req, res) -> if req.session console.log "logged in as '#{req.session.userLogin}'" res.render (req.params.template + '.pug') # socket.io web = http.Server app socket = new FFTCGSOCKET web, sharedSession sessionMiddleware # Create server web.listen 3000, -> console.log '[FFTCG] Listening on port 3000 ...' # Handle termination process.on 'SIGINT', -> socket.close() console.log '[FFTCG] shutting down after SIGINT' process.exit()