diff --git a/.dockerignore b/.dockerignore index a6c11f7..712e87b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ node_modules npm-debug.log **/*.xcf +**/*.bundle.js Dockerfile .dockerignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..719bfb3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/*.bundle.js diff --git a/Dockerfile b/Dockerfile index a330ccd..d25a918 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,6 @@ RUN yarn # copy code COPY . . -RUN yarn build # this is how we start CMD ["yarn", "start"] diff --git a/docker-compose.yml b/docker-compose.yml index e13cf93..5718a0c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,10 @@ services: # dbpass: juchie5OhH6eiQuujaoquievezoe9iXe fftcg: build: . + command: "yarn debug" restart: "no" + volumes: + - "${PWD}/src:/app/src" + - "${PWD}/static:/app/static" ports: - "8001:8080" diff --git a/inc/10-socket.coffee b/inc/10-socket.coffee deleted file mode 100644 index a89f626..0000000 --- a/inc/10-socket.coffee +++ /dev/null @@ -1,39 +0,0 @@ -# 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 diff --git a/package.json b/package.json index 31d9aaf..6f427a7 100644 --- a/package.json +++ b/package.json @@ -1,31 +1,35 @@ { "name": "node-fftcg", - "version": "0.0.2", + "version": "0.0.3", + "description": "FFTCG online using Socket.IO and CraftyJS on Node.js on Docker", "author": "JMM ", - "main": "server.js", + + "main": "server.coffee", "private": true, "license": "UNLICENSED", + "scripts": { "build": "webpack", - "start": "node server.js", - "watch": "yarn start & webpack --watch", + "watch": "webpack --watch", + "start": "webpack && coffee server.coffee", + "debug": "webpack --watch & coffee server.coffee", "test": "echo \"Error: no test specified\" && exit 1" }, + "devDependencies": { "@babel/core": "^7.1.6", "@babel/preset-env": "^7.1.6", "coffee-loader": "^0.9.0", - "css-loader": "^1.0.1", - "postcss-loader": "^3.0.0", - "sass-loader": "^7.1.0", - "style-loader": "^0.23.1", - "transform-loader": "^0.2.4", "autoprefixer": "^9.3.1", - "brfs": "^2.0.1", + "css-loader": "^1.0.1", + "postcss-loader": "^3.0.0", "node-sass": "^4.10.0", "precss": "^3.1.2", + "sass-loader": "^7.1.0", + "style-loader": "^0.23.1", + "webpack": "^4.25.1", "webpack-cli": "^3.1.2", @@ -36,11 +40,11 @@ }, "dependencies": { - "bcrypt": "*", + "bcrypt": "^3.0.2", "coffeescript": "^2.3.2", "express": "^4.16.4", - "helmet": "*", - "mysql": "*", + "helmet": "^3.15.0", + "mysql": "^2.16.0", "socket.io": "^2.2.0", "socket.io-client": "^2.2.0" } diff --git a/static/assets/board.xcf b/public_html/assets/board.xcf similarity index 100% rename from static/assets/board.xcf rename to public_html/assets/board.xcf diff --git a/static/assets/ff7.jpg b/public_html/assets/ff7.jpg similarity index 100% rename from static/assets/ff7.jpg rename to public_html/assets/ff7.jpg diff --git a/static/assets/ranx.jpg b/public_html/assets/ranx.jpg similarity index 100% rename from static/assets/ranx.jpg rename to public_html/assets/ranx.jpg diff --git a/static/game.html b/public_html/game.html similarity index 100% rename from static/game.html rename to public_html/game.html diff --git a/server.coffee b/server.coffee new file mode 100644 index 0000000..5896d84 --- /dev/null +++ b/server.coffee @@ -0,0 +1,60 @@ +# libraries +bcrypt = require('bcrypt') +express = require('express') +helmet = require('helmet') +http = require('http') +mysql = require('mysql') +path = require('path') +socketio = require('socket.io') + +# 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' + return + +app.use helmet() + +# Static content +app.use express.static path.resolve(__dirname, 'public_html') + +con = mysql.createConnection + host: 'tcgsql' + user: 'fftcg' + database: 'fftcg' + password: 'juchie5OhH6eiQuujaoquievezoe9iXe' + +con.connect (err) -> + if err + throw err + console.log 'Connected to TCGSQL!' + return + +# Server logic +io.on 'connection', (socket) -> + + console.log 'a user connected' + + socket.on 'disconnect', -> + # console.log('user disconnected'); + return + + socket.on 'login', (msg) -> + console.log 'message:', msg.uname, msg.password + saltRounds = 13 + + bcrypt.hash msg.password, saltRounds, (err, hash) -> + con.query 'INSERT INTO `users` (nick, pwd_hash) VALUES (\'' + msg.uname + '\', \'' + hash + '\');', (err, result) -> + if err + throw err + console.log 'Result: ' + result + return + return + + return + + return diff --git a/server.js b/server.js deleted file mode 100644 index a9268f7..0000000 --- a/server.js +++ /dev/null @@ -1,57 +0,0 @@ -// libraries -var - http = require('http'), - socketio = require('socket.io'), - mysql = require('mysql'), - bcrypt = require('bcrypt'), - express = require('express'), - helmet = require('helmet'); - -// 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); - }); - }); - - }); -}); diff --git a/webpack.config.js b/webpack.config.js index 67c79f9..f196f95 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -12,16 +12,11 @@ module.exports = { output: { filename: '[name].bundle.js', - path: path.resolve(__dirname, 'static') + path: path.resolve(__dirname, 'public_html') }, module: { rules: [ - { - loader: "transform-loader?brfs", - enforce: "post" - }, - { test: /\.css$/, use: ['style-loader', 'css-loader']