-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
71 lines (55 loc) · 2.07 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
//loading express module
const express= require('express');
//initializing express
const app= express();
// ======= TO AVOID CORS ERRORS ========
const cors = require('cors')
app.use(cors())
// ========================= USER AUTHENTICATION ================================
const passport=require('passport');
app.use(passport.initialize());
app.use(passport.session());
require("./config/passport")(passport);
// ========================= BODY PARSER ==================================
//loading the body parser module
const bodyparser= require('body-parser');
//making the request body in the JSON format
app.use(bodyparser.urlencoded({extended:false}));
app.use(bodyparser.json());
// ========================= MONGO DB ==================================
/*
const config= require('./config/database');
//loading mongoose1 module
const mongoose = require('mongoose');
//creating the db connection
const connection =mongoose.connect(config.database);
//checking if connection is successful
if(connection){
console.log("Db Connection Successful!");
}else{
console.log("Db Connection Failed!");
}
*/
// ========================= PATH ==================================
//loading files system module
const path= require('path');
//defining the path to the static html files
app.use(express.static(path.join(__dirname,"public")));
// ======================= ROUTE HANDLING ===========================
//getting the user route
const userRoute= require('./routes/users');
app.use('/user',userRoute);
app.use('/user/register',userRoute);
//getting the leaderboard route
const leaderboardRoute= require('./routes/leaderboard');
app.use('/leaderboard',leaderboardRoute);
//defining a route for TESTING
app.get('/',(req,res)=>{
res.send("NOTE : This will be replaced by the static html in the public folder when an index.html file is in that folder");
});
// =========================== PORT ===============================
//defining the PORT and making the server listen to that port
const PORT= process.env.PORT || 3000;
app.listen(PORT,()=>{
console.log("Listening to port " + PORT);
});