-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
79 lines (52 loc) · 1.97 KB
/
Copy pathserver.js
File metadata and controls
79 lines (52 loc) · 1.97 KB
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
// 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) {
res.sendFile(path.join(__dirname, "app/public/survey.html"));
});
app.get("/match", function(req, res) {
res.sendFile(path.join(__dirname, "app/public/survey.html"));
});
// apiRoutes
//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;
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;
newEmployer.routeName = newEmployer.name.replace(/\s+/g, "").toLowerCase();
candidates.push(newEmployer);
res.json(newEmployer);
});
// Starts the server to begin listening
// =============================================================
app.listen(PORT, function() {
console.log("App listening on PORT " + PORT);
});