-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
50 lines (43 loc) · 1.58 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Main file to run on server.
* Starts express server to serve files to client.
* Sets up game lobby.
*/
//Import express server
var express = require('express');
var http = require('http')
//Import lobby setup.
var LobbyServer = require('./server/lobby.server.js');
/**
* Set up express server and lobby..
*/
var Setup = function(){
//The express server handles passing our content to the browser.
// Set the gameport for express server.
var gameport = process.env.PORT || 4004;
//Create the express server.
var expressServer = express();
//Something so we know that it succeeded.
console.log(':: Express :: Listening on port ' + gameport );
//All requests are redirected to the homepage.
//By default, we forward the / path to index.html automatically.
expressServer.get( '/', function( req, res ){
//Send the requesting client the homepage.
res.sendfile( __dirname + '/index.html' );
});
//This handler will listen for requests on /*, any file from the root of our server.
expressServer.get( '/*' , function( req, res, next ) {
//This is the current file they have requested
var file = req.params[0];
//Send the requesting client the file.
res.sendfile( __dirname + '/' + file );
});
//Set up lobby server and socket io message handler.
var lobbyServer = new LobbyServer();
httpServer = http.createServer(expressServer)
//Tell the server to listen for incoming connections
httpServer.listen( gameport );
lobbyServer.messageHandler(httpServer);
};
//Start express server and lobby setup.
Setup();