-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (42 loc) · 1.06 KB
/
index.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
const Picko = require('./server');
const picko = new Picko({
cors: {
origin: '*',
},
});
console.log(picko.app);
// Authentication for both Express and Socket.io
picko.authenticate((headers, callback) => {
if (headers.authorization === '555') {
callback(null, true); // Authorized
} else {
callback(401, false); // Unauthorized
}
});
picko.use('/testuse', (req, res) => {
res.send('All requests to /testuse are authenticated');
});
picko.get('/testuse', (req, res) => {
res.send('Get request received');
});
picko.get('/hello', (req, res) => {
res.send('Hello World!');
});
picko.post('/sad', (req, res) => {
res.send(req.body);
});
picko.put('/test', (req, res) => {
res.send({ 1: 9 });
});
picko.get('/users/:id/:state', (req, res) => {
const { id, state } = req.params;
// Do something with the user ID, like query a database
res.send(`User ${id} ${state} found!`);
});
picko.listen(3000, () => {
console.log('Server started on port 3000');
});
picko.post('/users', (req, res) => {
console.log(req.body);
res.send(req.body);
});