Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
79 lines (71 loc) · 1.99 KB
/
Copy pathserver.js
File metadata and controls
79 lines (71 loc) · 1.99 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
let projects = require("./data.json");
const express = require("express"); //Line 1
var cors = require("cors");
var app = express();
app.use(cors());
const port = process.env.PORT || 5000; //Line 3
// cors port at 3000
var corsOptions = {
origin: "http://localhost:3000",
};
// Uses cors, and express json/urlencoded
app.use(cors(corsOptions));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// This displays message that the server running and listening to specified port
app.listen(port, () => console.log(`Listening on port ${port}`)); //Line 6
//get project details given username and name of project
app.get("/projectDetails", (req, res) => {
let username = req.query.username;
let project = req.query.project;
const allProjects = [];
for (const i in projects) {
if (
projects[i].username === username &&
projects[i].projectName === project
) {
allProjects.push(projects[i]);
}
}
res.json(allProjects);
});
//get all projects for a given user
app.get("/userProjects", (req, res) => {
let username = req.query.username;
const allProjects = [];
for (const i in projects) {
if (projects[i].username === username) {
allProjects.push(projects[i]);
}
}
res.json(allProjects);
});
//get all projects
app.get("/projects", (req, res) => {
const allProjects = [];
for (const i in projects) {
allProjects.push(projects[i]);
}
res.json(allProjects);
});
//get all projects that are a specifc category
app.get("/categoryProjects", (req, res) => {
const category = req.query.category;
const allProjects = [];
for (const i in projects) {
if (projects[i].categories.includes(category)) {
allProjects.push(projects[i]);
}
}
res.json(allProjects);
});
//get all projects needing a mentor
app.get("/needMentors", (req, res) => {
const allProjects = [];
for (const i in projects) {
if (projects[i].mentorSearch === "true") {
allProjects.push(projects[i]);
}
}
res.json(allProjects);
});