-
Notifications
You must be signed in to change notification settings - Fork 0
/
httpserver.js
60 lines (42 loc) · 1.45 KB
/
httpserver.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
48
49
50
51
52
53
54
55
56
57
58
59
60
"use strict";
var express = require("express"),
exphbs = require("express-handlebars"),
http = require("http"),
bodyParser = require("body-parser"),
routes = require("./routes"),
lobby = require("./server/lobby"),
path = require("path"),
config = require("./config");
function initializeHttpServer(app) {
var port = process.env.PORT || 8080;
// Set handlebars as the templating engine
app.engine("handlebars", exphbs({
defaultLayout: "main"
}));
app.set("view engine", "handlebars");
// http://www.askapache.com/htaccess/apache-speed-etags.html
app.disable("etag");
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({
extended: false
}));
//app.use(express.cookieParser());
//app.use(express.session({secret: '1234567890QWERTY'}));
// parse application/json
app.use(bodyParser.json());
// Set /public as our static content dir
app.use("/", express.static(path.join(__dirname, "/public/")));
// Fire this bitch up (start our server)
return http.createServer(app).listen(port, function() {
config.eventHandlers.onLog("Expresss server listening on port " + port);
});
}
function setupRoutes(app) {
// Index Route
app.get("/", routes.index());
}
var app = express();
setupRoutes(app);
var httpServer = initializeHttpServer(app);
var io = require("socket.io")(httpServer);
lobby.listenForConnections(io);