Skip to content

Commit 918ce3b

Browse files
committed
fix(istio): github service fix
1 parent 599b2f3 commit 918ce3b

File tree

6 files changed

+32
-11
lines changed

6 files changed

+32
-11
lines changed

istio_examples/Services/api/src/server.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ app.get('/api', (req, res) => res.json({
1313
version: VERSION
1414
}))
1515
app.get('/api/git', async (req, res) => {
16-
console.log('sending request: http://github.default.svc.cluster.local:5000/api/v1')
17-
const response = await request({
18-
method: 'GET',
19-
uri: `http://github.default.svc.cluster.local:5000/api/v1`
20-
})
21-
res.json(response)
16+
try {
17+
const response = await request({
18+
method: 'GET',
19+
uri: `http://github.default.svc.cluster.local:5000/api/v1`
20+
})
21+
return res.json(JSON.parse(response))
22+
} catch (err) {
23+
console.log(err)
24+
return res.sendStatus(500)
25+
}
2226
})
2327

2428
app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`))

istio_examples/Services/deploy.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ done
1717

1818
kubectl delete ingress gateway
1919
kubectl apply -f <(istioctl kube-inject -f $DIR/ingress.yml)
20+
21+
kubectl delete egressrule github-egress
22+
kubectl apply -f <(istioctl kube-inject -f $DIR/egress.yml)

istio_examples/Services/egress.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: config.istio.io/v1alpha2
2+
kind: EgressRule
3+
metadata:
4+
name: github-egress
5+
label:
6+
app: github
7+
spec:
8+
destination:
9+
service: "*.github.com"
10+
ports:
11+
- port: 443
12+
protocol: https
13+
- port: 80
14+
protocol: http

istio_examples/Services/github/src/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"cors": "^2.8.4",
1414
"express": "4.16.2",
15+
"lodash": "^4.17.4",
1516
"request": "2.83.0",
1617
"request-promise-native": "1.0.5"
1718
}

istio_examples/Services/github/src/server.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@ const request = require('request-promise-native')
22
const express = require('express')
33
const app = express()
44
const cors = require('cors')
5+
const _ = require('lodash')
56
app.use(cors())
67

78
const PORT = process.env.PORT
89

910
app.get('/healthz', (req, res) => res.sendStatus(200))
1011
app.get('/api/v1', async (req, res) => {
11-
console.log(`request recieved!`)
1212
try {
1313
const {items} = await request({
1414
method: 'GET',
15-
uri: 'https://api.github.com/search/repositories',
15+
uri: 'http://api.github.com:443/search/repositories',
1616
headers: {
1717
Accept: 'application/vnd.github.v3+json',
1818
'User-Agent': 'RisingStack'
1919
},
2020
qs: { q: 'risingstack-bootcamp' },
2121
json: true
2222
})
23-
console.log(items)
24-
return res.send(items[0])
23+
return res.json(_.pickBy(items[0], _.identity))
2524
} catch (err) {
2625
console.log(err)
2726
return res.sendStatus(500)

istio_examples/Services/ui/src/src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class App extends Component {
3737
<button onClick={this.callAPIgit}>Call API git</button>
3838
<p></p>
3939
{!this.state.error
40-
? _.map(data, (value, key) => {return(<div key={key}>{key}: <b>{value}</b></div>)})
40+
? _.map(data, (value, key) => {return(<div key={key}>{key}: <b>{value.toString()}</b></div>)})
4141
: <div className="error">Error: <b>{this.state.data}</b></div>
4242
}
4343
</div>

0 commit comments

Comments
 (0)