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

48 lines
1 KiB
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')
socketio = (require 'socket.io')
# my libraries
fftcgdb = (require './inc/fftcgdb')
fftcgdb.open path.resolve(__dirname, 'fftcg.db')
# express + socket.io framework
app = express()
2018-12-07 09:38:46 +00:00
web = http.Server app
io = socketio web
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')
# Server logic
io.on 'connection', (socket) ->
console.log 'a user connected'
socket.on 'disconnect', ->
2018-12-07 09:38:46 +00:00
console.log 'a user disconnected'
return
socket.on 'login', (msg) ->
console.log 'message:', msg.uname, msg.password
2018-12-07 09:38:46 +00:00
fftcgdb.adduser msg.uname, msg.password
2018-12-07 09:38:46 +00:00
# Create server
web.listen 3000, ->
console.log '[FFTCG] Listening on port 3000 ...'
2018-12-07 09:38:46 +00:00
# Handle termination
process.on 'SIGINT', ->
console.log '[FFTCG] shutting down after SIGINT'
process.exit()