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

34 lines
761 B
CoffeeScript
Raw Normal View History

2018-12-07 09:38:46 +00:00
# node libraries
express = (require 'express')
helmet = (require 'helmet')
http = (require 'http')
path = (require 'path')
# my libraries
2018-12-14 22:41:43 +00:00
FFTCGSOCKET = (require './inc/fftcgsocket')
2018-12-14 06:03:03 +00:00
# express + socket framework
app = express()
app.use helmet()
# Static content
app.use express.static path.resolve(__dirname, 'public_html')
2018-11-29 13:47:18 +00:00
# Templates
app.set 'view engine', 'pug'
app.get '/:template.html', (req, res) ->
res.render (req.params.template + '.pug')
2018-12-07 09:38:46 +00:00
# Create server
2018-12-14 22:41:43 +00:00
web = http.Server app
2018-12-07 09:38:46 +00:00
web.listen 3000, ->
console.log '[FFTCG] Listening on port 3000 ...'
2018-12-14 22:41:43 +00:00
socket = new FFTCGSOCKET web, path.resolve(__dirname, 'fftcg.db')
2018-12-07 09:38:46 +00:00
# Handle termination
process.on 'SIGINT', ->
socket.close()
2018-12-07 09:38:46 +00:00
console.log '[FFTCG] shutting down after SIGINT'
process.exit()