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
2018-12-15 21:09:01 +01:00

59 lines
1.2 KiB
CoffeeScript

# node libraries
express = (require 'express')
expressSession = (require 'express-session')
sharedSession = (require 'express-socket.io-session')
helmet = (require 'helmet')
http = (require 'http')
path = (require 'path')
# my libraries
FFTCGSOCKET = (require './inc/fftcgsocket')
# express framework
app = express()
app.use helmet()
# sessions
session =
secret: 'keyboard cat'
cookie:
httpOnly: true
sameSite: 'strict'
proxy: true
resave: true
saveUninitialized: true
if app.get 'env' == 'production'
app.set 'trust proxy', 1
session.cookie.secure = true
sessionMiddleware = expressSession session
app.use sessionMiddleware
# Static content
app.use express.static path.resolve(__dirname, 'public_html')
# Templates
app.set 'view engine', 'pug'
app.get '/:template.html', (req, res) ->
res.render (req.params.template + '.pug')
# Create server
web = http.Server app
web.listen 3000, ->
console.log '[FFTCG] Listening on port 3000 ...'
# socket.io
socket = new FFTCGSOCKET(
web,
path.resolve(__dirname, 'fftcg.db'),
sharedSession sessionMiddleware
)
# Handle termination
process.on 'SIGINT', ->
socket.close()
console.log '[FFTCG] shutting down after SIGINT'
process.exit()