-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
66 lines (55 loc) · 1.84 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const express = require('express'); //import express
const bodyParser = require("body-parser"); //used to extract information from forms
const app = express(); //initiale a new express application
const port = 8000; //port this app will listen on
const userRouter = require("./backend/routes/user"); //load routes for users
const electionBodyRouter = require("./backend/routes/electionbody");
const voteRouter = require("./backend/routes/vote");
const electionRouter = require("./backend/routes/election");
<<<<<<< HEAD
=======
const clientRouter = require("./backend/routes/client");
>>>>>>> f4a02e3e56d5d97f74d8e4f69f4a07bd6478e087
const analyticsRouter = require("./backend/routes/analytics");
/*
Set up mongodb/mongoose
*/
const mongoose = require('mongoose');
let uri = "mongodb://easyvote:[email protected]:43963/easyvote"
mongoose.connect(uri, {useNewUrlParser: true}).then(()=>{
console.log("Connected to Database");
}).catch((err)=>{
console.log(`Error in connection to DB ${err}`);
})
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "*");
next();
});
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended:true}))
/*
Configure routes
*/
app.use('/user', userRouter);
app.use('/electionBody', electionBodyRouter);
app.use('/vote', voteRouter);
app.use('/election', electionRouter);
<<<<<<< HEAD
app.use('/client', clientRouter);
app.use('/analytics', analyticsRouter);
app.use('/analytics', analyticsRouter);
=======
app.use('/client', clientRouter);
app.use('/analytics', analyticsRouter);
>>>>>>> f4a02e3e56d5d97f74d8e4f69f4a07bd6478e087
//used to test if server is running
app.get('/', (req,res)=>{
res.send("Hello world"); //prints hello world
});
/*
Run server
*/
app.listen(port, ()=> {
console.log(`App is listening on port ${port}`);
})