-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
55 lines (42 loc) · 1.73 KB
/
app.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
var welcome = require('./welcome.js');
var colors = require('colors');
//Loading Config:
var configfunctions = require('./connection/configfunctions.js');
configfunctions.loadInitialConfigSync(__dirname+"/config.json");
var express = require('express');
var connection = require('./connection/connection.js');
var login = require('./connection/login.js');
var config = require('./connection/config.js');
var config2 = require('./config.json');
var mongoose = require('mongoose');
require('socket.io-client');
var app = express();
// Loading Database:
var db = mongoose.connect(config2.global.db || "mongodb://localhost/stockparty");
// Check Default user
var userInterface = require('./database/UserInterface.js');
userInterface.init(function(err){
console.error('Failed to generate default admin user'.red);
});
app.get('/socket.io.js', function (req, res) {
res.sendFile(__dirname + '/node_modules/socket.io-client/socket.io.js');
});
app.get('/superagent.js', function (req, res) {
res.sendFile(__dirname + '/node_modules/superagent/superagent.js');
});
app.get('/server.txt', function (req, res) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.send('StockParty Server by David Ehlen, Robin Frischmann, Nils Hirsekorn, Dustin Hoffner');
});
app.use(express.static(__dirname + '/public'));
app.use('/apis', express.static(__dirname + '/apis'));
var io = require('socket.io').listen(app.listen(config.data.global.port));
io.sockets.on('connection', function (socket) {
console.log('Connected '+socket.id);
socket.loggedId = false;
login.use(socket);
socket.on('disconnect', function () {
console.log('Disconnected '+socket.id);
});
});