-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
55 lines (43 loc) · 1.65 KB
/
server.js
File metadata and controls
55 lines (43 loc) · 1.65 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
const express = require('express');
const app = express();
const port = 3000;
const path = require('path');
const data = require('./MOCK_DATA');
app.use(function(req, res, next){
console.log(`${req.method} request for ${req.url}`);
next();
});
app.use(express.static('./public'));
app.get('/aboutProject', function(req, res){
res.sendFile(path.join(__dirname + '/public/about.html'));
});
//Jquery
//Popper.js
app.use('/jquery', express.static(path.join(__dirname, 'node_modules/jquery/dist')));
app.use('/popper', express.static(path.join(__dirname, 'node_modules/popper.js/dist/umd')));
app.use('/bootstrap', express.static(path.join(__dirname, 'node_modules/bootstrap/dist')));
// Make an AJax request in your script.js file to return this data
app.get('/people', function(req, res){
res.json(data);
});
app.get('/gender/g=:gender', function(req, res){
const genderParam = req.params.gender;
if( (genderParam === 'male') || (genderParam === 'female') ){
let filteredData = [];
for (var i = 0; i < data.length; i++) {
if(genderParam === data[i].gender.toLowerCase()){
filteredData.push(data[i]);
}
}
res.send(filteredData);
} else {
res.send('Invalid Parameter')
}
});
// app.get('/', (req, res) => res.send('Hello World'));
// app.get('/about', (req, res) => res.send('This is the about page'));
// app.get('/contact', (req, res) => res.send('This is the contact page'));
// app.get('/about/me', (req, res) => res.send('This is the about me page'));
// app.get('/about/us', (req, res) => res.send('This is the about us page'));
// app.post();
app.listen(port, () => console.log(`application is running on port ${port}`));