From 68c63563ef93b8516dc189c2a87eb44cb1f02335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= Date: Thu, 4 Oct 2018 00:07:17 +0200 Subject: [PATCH] Testing coffeescript in nodejs --- package.json | 1 + server/scripts/10-socket.coffee | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 server/scripts/10-socket.coffee diff --git a/package.json b/package.json index 0344a61..efa8c7c 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "express": "^4.16.1", "helmet": "*", "socket.io": "^2.1.1", + "coffeescript": "*", "merge-stream": "*", "gulp": "*", "gulp-sourcemaps": "*", diff --git a/server/scripts/10-socket.coffee b/server/scripts/10-socket.coffee new file mode 100644 index 0000000..a89f626 --- /dev/null +++ b/server/scripts/10-socket.coffee @@ -0,0 +1,39 @@ +# libraries +http = require 'http' +socketio = require 'socket.io' +express = require 'express' +gulp = global.gulp = require 'gulp' +helmet = require 'helmet' + +# gulp the sources +require './gulpfile' +gulp.start 'default' + +# socket.io framework +app = express() +web = http.Server app +io = socketio web + +# Listen server +web.listen 8080, -> + console.log 'Node.js listening on port 8080' + +app.use helmet() + +# Static content +app.use ( express.static __dirname + '/../static' ) + +# Server logic +io.on 'connection', (socket) -> + console.log 'a user connected' + console.log socket.id + + socket.on 'disconnect', -> + # console.log 'user disconnected' + return + + socket.on 'login', -> + console.log 'message:', msg.uname, msg.password + return + + return