-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (42 loc) · 1.5 KB
/
server.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
'use strict';
const
express = require("express"),
http = require("http"),
path = require("path"),
mongoose = require("mongoose" ),
winston = require("winston"),
ConnectionHandler = require('./connectionHandlerServer');
const
DATABASE = 'freedomDb',
COLLECTION = 'jumpAndRunGame',
mongoDbHostname = process.env.MONGO || "localhost", //The process.env property returns an object containing the user environment.
mongoDbUrl = 'mongodb://' + path.join(mongoDbHostname, DATABASE ),
PORT = process.env.PORT || 8080,
PUBLICPATH = path.join( __dirname, 'client' ),
app = express(),
server = http.Server( app ),
logger = new ( winston.Logger )({
transports: [
new ( winston.transports.Console )({
level: 'debug',
handleExceptions: true,
json: false,
colorize: true
})
]
});
//Zeige Express, wo die Dateien fuer den Client liegen.
app.use( '/client', express.static( PUBLICPATH ) );
//Schickt die index.html auf anfrage des Client nach den Root.
app.get('/', function( req, res ) {
res.sendFile( path.join( PUBLICPATH, 'index.html') );
});
//Fuer alle anderen Anfragen wird ein 404 geloggt und die index.html geschickt.
app.get('*', function( req, res ){
logger.info( '404 for your-domain.com' + req.url );
res.sendFile( path.join( PUBLICPATH, 'index.html' ) );
});
//Starte Server
server.listen( PORT );
logger.debug( 'Server is running on Port: ' + PORT );
let connectionHandler = new ConnectionHandler( server, mongoose, mongoDbUrl, COLLECTION );