// libraries var http = require('http'), socketio = require('socket.io'), mysql = require('mysql'), bcrypt = require('bcrypt'), express = require('express'), gulp = global.gulp = require('gulp'), helmet = require('helmet'); // gulp the sources require('./gulpfile'); gulp.start('default'); // socket.io framework let app = express(); let web = http.Server(app); let io = socketio(web); // Listen server web.listen(8080, function () { console.log('Node.js listening on port 8080'); }); app.use(helmet()); // Static content app.use(express.static(__dirname + '/static')); var con = mysql.createConnection({ host: "tcgsql", user: "fftcg", database: "fftcg", password: "juchie5OhH6eiQuujaoquievezoe9iXe", }); con.connect(function(err) { if (err) throw err; console.log("Connected to TCGSQL!"); }); // Server logic io.on('connection', function (socket) { console.log('a user connected'); socket.on('disconnect', function(){ // console.log('user disconnected'); }); socket.on('login', function(msg){ console.log('message:', msg.uname, msg.password); const saltRounds = 13; bcrypt.hash(msg.password, saltRounds, function(err, hash) { con.query('INSERT INTO `users` (nick, pwd_hash) VALUES (\'' + msg.uname + '\', \'' + hash + '\');', function (err, result) { if (err) throw err; console.log("Result: " + result); }); }); }); });