Skip to content

Commit

Permalink
Use ENV vars to get the API endpoint and default hostname for the ser…
Browse files Browse the repository at this point in the history
…ver-side rendering
  • Loading branch information
matsimitsu committed Sep 6, 2021
1 parent 48d3753 commit 63751ad
Show file tree
Hide file tree
Showing 7 changed files with 9,800 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
NEXT_PUBLIC_API_MOCKING=enabled
NEXT_PURGE_CSS=enabled
NEXT_TELEMETRY_DISABLED=1
DEFAULT_HOSTNAME="staging.appsignal-status.online"
API_ENDPOINT="api.appsignal-status.online"
14 changes: 3 additions & 11 deletions components/UptimeMonitor/UptimeMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const UptimeMonitorLoading = () => {
);
};

const UptimeMonitor = ({ hostname, uptimeMonitor }) => {
const UptimeMonitor = ({ uptimeMonitor }) => {
const [overlayOpen, setOverlayOpen] = React.useState(false);
const [loading, setLoading] = React.useState(true);
const [monitor, setMonitor] = React.useState([]);
Expand All @@ -33,14 +33,7 @@ const UptimeMonitor = ({ hostname, uptimeMonitor }) => {
// We use the mounted variable to make sure React stops trying to use state
// when the component is unmounted.
let mounted = true;
fetch(
`https://api.appsignal-status.online/status_pages/${Buffer.from(
hostname
).toString("base64")}/monitors/${uptimeMonitor.id}.json`,
{
mode: "cors",
}
)
fetch(uptimeMonitor.endpoint, { mode: "cors" })
.then((res) => res.json())
.then((result) => {
if (mounted) {
Expand All @@ -50,7 +43,7 @@ const UptimeMonitor = ({ hostname, uptimeMonitor }) => {
});

return () => (mounted = false);
}, [hostname, uptimeMonitor.id]);
}, [uptimeMonitor.id, uptimeMonitor.endpoint]);

return (
<>
Expand Down Expand Up @@ -86,7 +79,6 @@ const UptimeMonitor = ({ hostname, uptimeMonitor }) => {

UptimeMonitor.propTypes = {
uptimeMonitor: PropTypes.object.isRequired,
hostname: PropTypes.string.isRequired,
};

export default UptimeMonitor;
1 change: 0 additions & 1 deletion components/UptimeMonitor/UptimeMonitor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import statusPageMock from "../../mocks/status_pages/appsignal.json";
const build = (props = {}) => {
return render(
<UptimeMonitor
hostname="example.com"
uptimeMonitor={statusPageMock.uptime_monitors[0]}
{...props}
/>
Expand Down
7 changes: 1 addition & 6 deletions components/UptimeMonitors/UptimeMonitors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ const UptimeMonitors = ({ statusPage }) => {
}

return statusPage.uptime_monitors.map((monitor) => (
<UptimeMonitor
key={monitor.url}
uptimeMonitor={monitor}
hostname={statusPage.hostname}
/>
<UptimeMonitor key={monitor.url} uptimeMonitor={monitor} />
));
};
return (
Expand All @@ -32,7 +28,6 @@ const UptimeMonitors = ({ statusPage }) => {

UptimeMonitors.propTypes = {
statusPage: PropTypes.shape({
hostname: PropTypes.string.isRequired,
uptime_monitors: PropTypes.array.isRequired,
}).isRequired,
};
Expand Down
9 changes: 6 additions & 3 deletions mocks/status_pages/appsignal.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@
"title": "homepage",
"url": "https://www.appsignal.com",
"description": "The AppSignal homepage. Notify #operations when this alert is triggered. ",
"regions": ["europe", "south-america", "north-america", "asia-pacific"]
"regions": ["europe", "south-america", "north-america", "asia-pacific"],
"endpoint": "https://api.appsignal-status.online/status_pages/1/monitors/homepage.json"
},
{
"id": "blog",
"title": "blog",
"url": "https://blog.appsignal.com",
"description": "",
"regions": ["europe", "south-america", "north-america", "asia-pacific"]
"regions": ["europe", "south-america", "north-america", "asia-pacific"],
"endpoint": "https://api.appsignal-status.online/status_pages/1/monitors/blog.json"
},
{
"id": "always-down",
"title": "Always Down",
"url": "https://banana.appsignal.com",
"description": "This endpoint will always be down!",
"regions": ["europe", "south-america", "north-america", "asia-pacific"]
"regions": ["europe", "south-america", "north-america", "asia-pacific"],
"endpoint": "https://api.appsignal-status.online/status_pages/1/monitors/always-down.json"
}
]
}
Loading

1 comment on commit 63751ad

@vercel
Copy link

@vercel vercel bot commented on 63751ad Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.