-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
51 lines (45 loc) · 890 Bytes
/
example.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
49
50
51
const swiftJs = require('./');
var app = swiftJs();
app.get('/', (req, res, next) => {
console.log('query params', req.query)
res.send('<h1>text</h1>');
})
app.get("/products/:id", (req, res) => {
console.log('req', req.params.id);
res.json({
id: req.params.id,
title: 'Test Product',
price: 10
});
});
app.get("/products", (req, res) => {
res.json({
count: 1,
items: [{
id: 1,
title: 'Test Product',
price: 10
}]
});
});
app.get('/orders', (req, res, next) => {
if (req.headers['authorization'] === 'JWT token') {
console.log('next', next)
next()
} else {
res.statusCode = 401;
res.send('Not allowed')
}
}, (req, res) => {
res.json({
count: 1,
items: [{
id: 1,
title: 'Test order',
price: 10
}]
});
});
app.listen(3000, () => {
console.log('Server running on 3000');
})