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
953 B
CoffeeScript

# node libraries
# (require 'debug').enable 'FFTCG'
logger = (require 'logging').default 'FFTCG'
fastify = (require 'fastify')
logger: level: 'warn'
path = (require 'path')
# my libraries
socket = (require './socket')
# FFTCGSESSION = (require './session')
routes = (require './routes')
# fastify framework
fastify.register (require 'fastify-cookie')
fastify.register (require 'fastify-ws'), library: 'uws'
fastify.register (require 'fastify-static'), root: (path.join __dirname, 'tmpfront')
fastify.ready()
.then ->
fastify.ws.on 'connection', socket
.catch (err) ->
logger.error err
process.exit 1
fastify.addHook 'onRequest', (req, res, next) ->
logger.debug 'requested', req.url
next()
fastify.route route for route in routes
fastify.listen 3001, '0.0.0.0'
.catch (err) ->
logger.error err
# Handle termination
process.on 'SIGINT', ->
socket.close()
logger.info 'shutting down after SIGINT'
process.exit()