use node http server

This commit is contained in:
Tim Meier 2016-06-04 09:30:47 +02:00
parent e0c4d9705c
commit a0ad60d21b
6 changed files with 44 additions and 42 deletions

5
.gitignore vendored
View File

@ -1,6 +1,7 @@
node_modules node_modules
.idea .idea
public/ !public/Config.js
public
test/spec test/spec
assets/cards/* assets/cards/*
client/scss/_cards.scss client/scss/_cards.scss
@ -11,4 +12,4 @@ client/scss/_cards.scss
/site/client/node_modules /site/client/node_modules
/site/public/assets/js/bundle.js /site/public/assets/js/bundle.js
/site/public/assets/css/app.css /site/public/assets/css/app.css
site/server/composer.lock site/server/composer.lock

View File

@ -1,16 +0,0 @@
window.Config = {};
Config.Server = {
"hostname": "192.168.123.1",
"port": 16918,
secure: false
}
Config.Gwent = {
notification_duration: 4000
}
Config.Site = {
base: "/gwent-online/site/public"
}

View File

@ -7,12 +7,10 @@ Not-Gwent-Online is a standalone multiplayer version of Gwent, a card game from
##- Requirements ##- Requirements
- [node.js](https://nodejs.org/) installed - [node.js](https://nodejs.org/) installed
- [GraphicsMagick](http://www.graphicsmagick.org) installed (for generating sprites) - [GraphicsMagick](http://www.graphicsmagick.org) installed (for generating sprites)
- Any Webserver like xampp, wamp, lamp etc
##- Build ##- Build
Make sure to clone the project in your webserver root folder, otherwise you won't be able to access your client later.
The root folder is often called 'www' or 'htdocs', but depends on your installed webserver. ```sh
```git
cd ~/myWebserverRoot cd ~/myWebserverRoot
git clone https://github.com/exane/not-gwent-online git clone https://github.com/exane/not-gwent-online
cd not-gwent-online cd not-gwent-online
@ -24,13 +22,12 @@ npm run build
##- Config ##- Config
- go to /public and open Config.js - go to /public and open Config.js
- change hostname to your address. (e.g., "192.168.123.1") <br>Make sure you don't have a trailing slash after your IP or address. (e.g., "192.168.123.1/") - change hostname to your address. (e.g., "192.168.123.1") <br>Make sure you don't have a trailing slash after your IP or address. (e.g., "192.168.123.1/")
- If you have to change the port then make sure you change the port on your server as well. <br>You find the server port in /server/server.js on line #18 "app.listen(#port)";
##- Start Server ##- Start Server
``` ```sh
cd ~/myProjectDirectory/not-gwent-online cd ~/myProjectDirectory/not-gwent-online
node server/server.js node server/server.js
``` ```
##- Start Client ##- Start Client
- Open your browser and go to "192.168.123.1/not-gwent-online/public" or wherever you saved your project. - Open your browser and go to e.g. "http://192.168.123.1:4000"

View File

@ -5,7 +5,7 @@
"main": "gulpfile.js", "main": "gulpfile.js",
"dependencies": { "dependencies": {
"connect": "3.0.1", "connect": "3.0.1",
"express": "4.12.3", "express": "^4.13.4",
"gulp-rename": "^1.2.2", "gulp-rename": "^1.2.2",
"jquery-deferred": "^0.3.0", "jquery-deferred": "^0.3.0",
"minimist": "1.1.0", "minimist": "1.1.0",

View File

@ -1,16 +1,32 @@
window.Config = {}; var Config = {};
Config.Server = { Config.Server = {
"hostname": "localhost", "hostname": "127.0.0.1",
"port": 16918, "port": 16918
secure: false };
}
Config.WebServer = {
"port": 3000
};
Config.Gwent = { Config.Gwent = {
notification_duration: 4000 notification_duration: 4000
} };
Config.Site = { (function (name, definition){
base: "/gwent/site/public" if (typeof define === 'function'){ // AMD
} define(definition);
} else if (typeof module !== 'undefined' && module.exports) { // Node.js
module.exports = definition();
} else { // Browser
var theModule = definition(), global = this, old = global[name];
theModule.noConflict = function () {
global[name] = old;
return theModule;
};
global[name] = theModule;
}
})('Config', function () {
return Config;
});

View File

@ -1,5 +1,8 @@
var argv = require('minimist')(process.argv.slice(2)); var argv = require('minimist')(process.argv.slice(2));
var http = require("http");
var express = require('express');
var app = express();
var Config = require("../public/Config")
global.connections = require("./Connections")(); global.connections = require("./Connections")();
@ -9,17 +12,18 @@ global.Room = require("./Room");
global.User = require("./User"); global.User = require("./User");
/*global.Socket = require("./Socket");*/ var server = http.createServer(app);
global.io = require("socket.io").listen(server);
server.listen(Config.Server.port);
app.use(express.static('public'));
app.use('/public', express.static('public'));
app.use('/assets', express.static('assets'));
var app = require('http').createServer(); app.listen(Config.WebServer.port);
global.io = require("socket.io")(app);
app.listen(16918);
var admin = io.of("/admin"); var admin = io.of("/admin");
io.on("connection", function(socket) { //global connection io.on("connection", function(socket) { //global connection
var user; var user;
connections.add(user = User(socket)); connections.add(user = User(socket));