-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
45 lines (39 loc) · 1015 Bytes
/
Copy pathexample.js
File metadata and controls
45 lines (39 loc) · 1015 Bytes
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
const jetx = require('./index');
const app = new jetx();
app.get('/', function(req, res) {
res.send(`<h1>hello world from JetX</h1>
<p>
This is the the index page.
<br> This lib came with simple routing, middleware, and default 404 error page.
<br> Go try to hit an undefined route such as, <a href="http://localhost:8080/xxx">here</a>
</p>
`);
});
app.get('/test', function(req, res) {
const result = {
id: 1,
name: "test index",
xxx: "xxxxx"
}
res.json(result);
});
app.get('/test/:id', function(req, res) {
const result = {
id: req.input,
name: "erdi",
xxx: "xxxxx"
}
res.json(result);
});
app.post('/', function(req, res) {
res.json({
message: 'this is the POST response',
body: req.body
})
});
// using middleware
const mymiddleware = (req, res) => {
console.log('incoming request', (new Date).getTime(), req.url)
}
app.use(mymiddleware);
app.listen(8080);