forked from AlexisNi/backMobi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
105 lines (86 loc) · 3.58 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var mongoose=require('mongoose');
var app = express();
var cors=require('cors');
var config= require('./config/config.js');
var compression = require('compression');
var helmet = require('helmet')
////////////////Node js fireBase////////////////////
var admin = require("firebase-admin");
var serviceAccount = require("./config/football-quiz-a9e1e-firebase-adminsdk-huyqg-1f82e47ba0.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://football-quiz-a9e1e.firebaseio.com"
});
var adminControl= require("./config/firebaseMiddleware");
///////////////////routes config////////////////////
var authethenticationRoute=require('./routes/authentication');
var userRoutes=require('./routes/user');
var arenaRoutes=require('./routes/arenas');
var activeArena=require('./routes/activeArena');
var awards=require('./routes/awards');
var firebaseRoutes=require('./routes/firebaseAuth');
var historicDataRoutes=require('./routes/historicData');
var leaderBoardRoutes=require('./routes/leaderBoard');
require('./controllers/leaderboard').leaderBoardCreate();
setInterval(function () {
require('./controllers/leaderboard').leaderBoardCreate();
},600000)
///////////////socket config//////////////////
var mongoAdapter = require('socket.io-adapter-mongo');
var socket_io=require("socket.io");
var io=socket_io();
app.io=io;
io.adapter(mongoAdapter('mongodb://Alexis:315551@ds153689.mlab.com:53689/footballquizarena' ));
var sockets=require('./sockets/socket')(io);
///////////////database//////////////////
mongoose.connect( 'Alexis:315551@ds153689.mlab.com:53689/footballquizarena');
// view engine setup
app.use(compression());
app.use(helmet());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(cors());
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
res.header("Access-Control-Allow-Headers", "Content-Type");
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
next();
});
/*
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:8100');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
*/
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');
app.use('/api/auth',authethenticationRoute);
app.use('/api/users',userRoutes);
app.use('/api/arenas',arenaRoutes);
app.use('/api/activeArena',activeArena);
app.use('/api/awards',awards);
app.use('/api/firebase',firebaseRoutes);
app.use('/api/historicData',historicDataRoutes);
app.use('/api/leaderBoard',leaderBoardRoutes)
app.use(function (req, res, next) {
return res.render('index',{title:'Express and port listeninig is'+process.env.pp + ' process '+ process.env.WEB_CONCURRENCY });
});
module.exports = app;