-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path_index.js
38 lines (32 loc) · 836 Bytes
/
_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
const pico = require('./app');
const app = pico();
app.get("/products/:id", (req, res) => {
console.log("query params", req.query);
console.log('req.params', req.params);
res.send("product id");
});
app.get('/products', (req, res) => {
console.log('query params', req.query)
res.send('text');
})
app.post('/products', (req,res) => {
console.info('body', req.body)
res.json(req.body);
})
// TODO make this work
app.get('/orders', (req, res, next) => {
if (req.headers['authorization'] === 'abc123') {
console.log('next', next)
next()
} else {
res.statusCode = 401;
res.send('Not allowed')
}
}, (req, res) => {
res.send('Protected route');
})
// TODO query parameters
// TODO middleware function middleware(req, res, next) {}
app.listen(3000, () => {
console.log('Server running on 3000');
})