-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
98 lines (65 loc) · 2.62 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
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
// REQUIRE MODULES
var express = require('express'),
app = express(),
controller = require('./controllers'),
bodyParser = require('body-parser');
// CONFIGURE APP
app.use(bodyParser.urlencoded({ extended: true }));
// serve static files from public folder
app.use(express.static(__dirname + '/public'));
// set view engine to ejs
app.set("view engine", "ejs");
// Allow CORS: we'll use this today to reduce security so we can more easily test our code in the browser.
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
/**********
* ROUTES *
***********/
//HTML ENDPOINTS
app.get('/', function homepage(req, res) {
res.sendFile(__dirname + '/views/index.html');
});
//changed above endpoint to go to landing html...we can remove this, or replace index.html with landing.html
app.get('/landing', function homepage(req, res) {
res.sendFile(__dirname + '/views/landing.html');
});
app.get('/background_test', function homepage(req, res) {
res.sendFile(__dirname + '/views/background_test.html');
});
app.get("/quiz", controller.questions.list);
app.get('/marvel_quiz', function homepage(req, res) {
res.sendFile(__dirname + '/views/marvel_quiz.html');
});
//testing map_test
app.get('/map_test', function homepage(req, res) {
res.sendFile(__dirname + '/views/map_test.html');
});
//JSON API ENDPOINTS
//QUIZ ENDPOINTS
app.get('/api/quiz', controller.quizzes.index);
app.post('/api/quiz', controller.quizzes.create); //admins only
app.get('/api/quiz/:id', controller.quizzes.show); //admins only
app.put('/api/quiz/:id', controller.quizzes.update); //admins only
app.delete('/api/quiz/:id', controller.quizzes.destroy); //admins only
//QUESTIONS ENDPOINTS
app.get('/api/questions', controller.questions.index); // admins only
app.post('/api/questions', controller.questions.create); // admins only
app.get('/api/questions/:id', controller.questions.show); //admins only
app.put('/api/questions/:id', controller.questions.update); //admins only
app.delete('/api/questions/:id', controller.questions.destroy); //admins only
//ANSWERS ENDPOINTS
app.get('/api/answers', controller.answers.index);
app.post('/api/answers', controller.answers.create);
app.get('/api/answers/:id', controller.answers.show);
app.put('/api/answers/:id', controller.answers.update);
app.delete('/api/answers/:id', controller.answers.destroy);
/**********
* SERVER *
***********/
//listen on port 3000
app.listen(process.env.PORT || 3000, function() {
console.log('Server running on http://localhost:3000');
});