-
Notifications
You must be signed in to change notification settings - Fork 0
/
server-Pumpkin7.js
executable file
·118 lines (83 loc) · 3.32 KB
/
server-Pumpkin7.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
106
107
108
109
110
111
112
113
114
115
116
117
118
// Charles Goodwin/node express app for matiching individuals or items by similar answers to questions
// Dependencies
// =============================================================
var express = require("express");
var bodyParser = require("body-parser");
var path = require("path");
// Express config
// Sets up the Express App
// =============================================================
var app = express();
// Set port for listening
var PORT = process.env.PORT || 3000;
// Set Express app to handle data parsing
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Routes
// =============================================================
// Basic route that sends the user first to the AJAX Page
require("./app/routes/apiRoutes")(app);
require("./app/routes/htmlRoutes")(app);
// htmlRoutes
app.get("/", function(req, res) {
res.sendFile(path.join(__dirname, "app/public/home.html"));
});
app.get("/survey", function(req, res) {
console.log("getting survery")
res.sendFile(path.join(__dirname, "app/public/survey.html"));
});
// apiRoutes
// Displays all candidates
// app.get("/api/candidates", function(req, res) {
// return res.json(candidates);
// });
// Displays a single character, or returns false
app.get("/api/candidates/:candidate", function(req, res) {
var chosen = req.params.candidate;
console.log(chosen);
for (var i = 0; i < candidates.length; i++) {
if (chosen === candidates[i].routeName) {
return res.json(candidates[i]);
}
}
return res.json(false);
});
// // Create New Characters - takes in JSON input
// app.post("/api/candidates", function(req, res) {
// // req.body hosts is equal to the JSON post sent from the user
// // This works because of our body-parser middleware
// var newCandidate = req.body;
// // Using a RegEx Pattern to remove spaces from newCharacter
// // You can read more about RegEx Patterns later https://www.regexbuddy.com/regex.html
// newcharacter.routeName = newcharacter.name.replace(/\s+/g, "").toLowerCase();
// console.log(newCandidate);
// candidates.push(newCandidate);
// res.json(newcharacter);
// });
app.post("/api/candidates", function(req, res) {
// req.body hosts is equal to the JSON post sent from the user
// This works because of our body-parser middleware
var newCandidate = req.body;
// Using a RegEx Pattern to remove spaces from newCharacter
// You can read more about RegEx Patterns later https://www.regexbuddy.com/regex.html
newcharacter.routeName = newcharacter.name.replace(/\s+/g, "").toLowerCase();
console.log(newCandidate);
candidates.push(newCandidate);
res.json(newcharacter);
});
app.post("/api/employers", function(req, res) {
// req.body hosts is equal to the JSON post sent from the user
// This works because of our body-parser middleware
var newEmployer = req.body;
// Using a RegEx Pattern to remove spaces from newCharacter
// You can read more about RegEx Patterns later https://www.regexbuddy.com/regex.html
newEmployer.routeName = newEmployer.name.replace(/\s+/g, "").toLowerCase();
console.log(newEmployer);
candidates.push(newEmployer);
res.json(newEmployer);
});
// Starts the server to begin listening
// =============================================================
app.listen(PORT, function() {
console.log("App listening on PORT " + PORT);
});