-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode.js
More file actions
52 lines (47 loc) · 1.31 KB
/
node.js
File metadata and controls
52 lines (47 loc) · 1.31 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
const express = require('express');
const app = express();
const data = require('./data.json');
// CORS middleware
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', 'https://quentincloudsnow.github.io');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
if (req.method === 'OPTIONS') {
res.sendStatus(200);
} else {
next();
}
});
app.get('/checkUser', (req, res) => {
const { firstname, lastname, dateofbirth } = req.query;
const user = data.find(user =>
user.firstname === firstname &&
user.lastname === lastname &&
user.dateofbirth === dateofbirth
);
if (user) {
const response = {
code: 0,
message: 'User exists',
user: {
guest_title: user.guest_title,
phone: user.phone,
host_name: user.host_name,
host_id_number: user.host_id_number,
host_email: user.host_email,
guest_email: user.guest_email,
building_location: user.building_location,
access_expiration: user.access_expiration
}
};
res.status(200).json(response);
} else {
const response = {
code: 1,
message: 'User does not exist'
};
res.status(200).json(response);
}
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});