Skip to content

Commit 3accbdd

Browse files
committed
Updated App to correctly populate data from the backend.
1 parent f7b84e1 commit 3accbdd

File tree

5 files changed

+46
-32
lines changed

5 files changed

+46
-32
lines changed

example.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ params:
77
# Application config
88

99
# production host name
10-
productionHost: fe-test.commitzero.com
11-
productionBucket: fe-test.commitzero.com
10+
productionHostRoot: example.com
11+
productionFrontendHost: example.com
12+
productionBackendHost: api.example.com
1213

1314
# staging host name
14-
stagingHost: fe-test.commitzero.com
15-
stagingBucket: fe-test.commitzero.com
15+
stagingHostRoot: example.com
16+
stagingFrontendHost: example.com
17+
stagingBackendHost: api.example.com

src/App.js

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,58 @@
11
import React, { useEffect, useState } from "react";
2-
import logo from './commit-logo.png';
3-
import './App.css';
2+
import logo from "./commit-logo.png";
3+
import "./App.css";
44

5-
import './components/Info'
6-
import InfoPanel from './components/Info';
5+
import "./components/Info";
6+
import InfoPanel from "./components/Info";
77

88
// Set config based on the environment variable the build was run under.
9-
let config = {}
10-
if (process.env.NODE_ENV === 'production') {
11-
config = require('./config/production.json')
12-
} else if (process.env.NODE_ENV === 'staging') {
13-
config = require('./config/staging.json')
9+
let config = {};
10+
if (process.env.NODE_ENV === "production") {
11+
config = require("./config/production.json");
12+
} else if (process.env.NODE_ENV === "staging") {
13+
config = require("./config/staging.json");
1414
} else {
15-
config = require('./config/development.json')
15+
config = require("./config/development.json");
1616
}
1717

1818
function App() {
1919
const [data, setData] = useState({
2020
info: {},
21-
status: "Checking...",
22-
error: null
21+
error: null,
2322
});
2423

24+
const [status, setStatus] = useState({
25+
code: "Checking...",
26+
})
27+
2528
useEffect(() => {
26-
fetch(`https://${config.backendURL}/status/about`)
27-
.then(result => setData({
28-
info: result.data,
29-
status: result.status
30-
}))
31-
.catch(error => setData({
32-
info: {},
33-
status: "Failed.",
34-
error: error.message
35-
}))
29+
fetch(`${config.backendURL}/status/about`)
30+
.then(result => {
31+
setStatus({
32+
code: result.status,
33+
})
34+
return result.json()
35+
})
36+
.then(data => {
37+
setData({
38+
info: data,
39+
error: null
40+
})
41+
})
42+
.catch(error => {
43+
setData({
44+
info: {},
45+
error: error
46+
})
47+
});
3648
}, []);
3749

3850
return (
3951
<div className="App">
4052
<header className="App-header">
4153
<img src={logo} className="App-logo" alt="logo" />
4254
<h1>zero</h1>
43-
<InfoPanel data={data} config={config} />
55+
<InfoPanel data={data} status={status} config={config} />
4456
</header>
4557
</div>
4658
);

src/components/Info.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react'
33

44
import './Info.css'
55

6-
const InfoPanel = ({ data, config }) => {
6+
const InfoPanel = ({ data, status, config }) => {
77
return (
88
<div className="info">
99
<h2>App Info</h2>
@@ -12,8 +12,8 @@ const InfoPanel = ({ data, config }) => {
1212
<strong>Application Name:</strong> {config.appName}<br />
1313
<strong>Environment:</strong> {config.environment}<br />
1414
{ data.info !== undefined ? <span><strong>Pod Name:</strong> {data.info.podName}<br /></span> : null}
15-
<strong>Status:</strong> {data.status}<br />
16-
{ data.error !== null ? <span className="error"><strong>Error:</strong> { data.error }</span> : null}
15+
<strong>Status:</strong> {status.code}<br />
16+
{ data.error !== null ? <span className="error"><strong>Error:</strong> { status.error }</span> : null}
1717
</p>
1818
</div></div>
1919
)

src/config/production.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"appName": "<% .Name %>",
33
"environment": "production",
4-
"backendURL": "<% index .Params `productionHost` %>"
4+
"backendURL": "https://<% index .Params `productionHost` %>"
55
}

src/config/staging.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"appName": "<% .Name %>",
33
"environment": "staging",
4-
"backendURL": "<% index .Params `stagingHost` %>"
4+
"backendURL": "https://<% index .Params `stagingHost` %>"
55
}

0 commit comments

Comments
 (0)