-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/api/fluxState endpoint; axios client to call it
- Loading branch information
Showing
10 changed files
with
205 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
.env | ||
kubeconfig.yaml | ||
build | ||
cmd/capacitor/web | ||
|
||
# dependencies | ||
web/node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Component } from 'react'; | ||
|
||
export default class APIBackend extends Component { | ||
|
||
componentDidMount() { | ||
this.props.capacitorClient.getFluxState() | ||
.then(data => console.log(data), () => {/* Generic error handler deals with it */ }); | ||
} | ||
|
||
render() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import axios from 'axios'; | ||
|
||
export default class CapacitorClient { | ||
constructor(onError) { | ||
this.onError = onError | ||
} | ||
|
||
URL = () => this.url; | ||
|
||
getFluxState = () => this.get('/api/fluxState'); | ||
|
||
get = async (path) => { | ||
try { | ||
const { data } = await axios.get(path, { | ||
credentials: 'include' | ||
}); | ||
return data; | ||
} catch (error) { | ||
this.onError(error.response); | ||
throw error.response; | ||
} | ||
} | ||
|
||
post = async (path, body) => { | ||
try { | ||
const { data } = await axios | ||
.post(path, body, { | ||
credentials: 'include', | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
return data; | ||
} catch (error) { | ||
this.onError(error.response); | ||
throw error.response; | ||
} | ||
} | ||
|
||
} |