This repository was archived by the owner on Jul 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
92 lines (81 loc) · 1.73 KB
/
index.js
File metadata and controls
92 lines (81 loc) · 1.73 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import 'global-agent/bootstrap.js';
import got from 'got';
import express from 'express';
import morgan from 'morgan';
const app = express()
app.use(morgan('tiny'))
const port = 3000
function makeError(err) {
let errMsg = {
'msg':'there was some error',
'err': err,
'ts': new Date().toISOString()
}
return errMsg
}
const errMsg = {
'err':'there was some error',
'ts': new Date().toISOString()
}
app.get('/', (req, res) => {
const body = {
'demo': 'node',
'ts': new Date().toISOString()
}
res.send(body);
})
app.get('/healthz', (req, res) => {
const body = {
health: 'y',
'ts': new Date().toISOString()
}
res.send(body);
})
app.get('/nasa', async (req, res) => {
try {
const url = 'https://api.nasa.gov/planetary/apod'
const options = {
searchParams: {
'api_key': 'DEMO_KEY'
}
}
const data = await got(url, options).json()
res.send(data)
} catch (err) {
const msg = makeError(err)
console.error(msg)
res.status(500)
res.send(msg)
}
})
app.get('/events', async (req, res) => {
try {
const url = 'https://api.github.com/orgs/speedscale/events';
const data = await got(url).json()
res.send(data)
} catch (err) {
const msg = makeError(err)
console.error(msg)
res.status(500)
res.send(msg)
}
})
app.get('/bin', async (req, res) => {
try {
const data = await got.post('https://httpbin.org/anything', {
json: {
host: 'httpbin',
endpoint: 'anything'
}
}).json()
res.send(data)
} catch (err) {
const msg = makeError(err)
console.error(msg)
res.status(500)
res.send(msg)
}
})
app.listen(port, () => {
console.log(`demo-node listening on port ${port}`)
})