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

42 lines
953 B
CoffeeScript
Raw Normal View History

2018-12-07 09:38:46 +00:00
# node libraries
2019-02-16 18:03:21 +00:00
# (require 'debug').enable 'FFTCG'
2019-02-07 16:03:20 +00:00
logger = (require 'logging').default 'FFTCG'
2019-02-16 18:03:21 +00:00
fastify = (require 'fastify')
logger: level: 'warn'
path = (require 'path')
2018-12-07 09:38:46 +00:00
# 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'
2019-02-15 12:06:16 +00:00
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
2019-02-16 18:03:21 +00:00
fastify.addHook 'onRequest', (req, res, next) ->
logger.debug 'requested', req.url
next()
2019-02-16 18:03:21 +00:00
fastify.route route for route in routes
fastify.listen 3001, '0.0.0.0'
.catch (err) ->
logger.error err
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()