mirror of
https://github.com/Lissy93/dashy.git
synced 2024-12-28 11:25:25 +03:00
⚡ Refactored NetData and HealthChecks with mixin request
This commit is contained in:
parent
e3f2b910ec
commit
1914d25b45
@ -17,9 +17,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
|
||||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||||
import { widgetApiEndpoints, serviceEndpoints } from '@/utils/defaults';
|
import { widgetApiEndpoints } from '@/utils/defaults';
|
||||||
import { capitalize, timestampToDateTime } from '@/utils/MiscHelpers';
|
import { capitalize, timestampToDateTime } from '@/utils/MiscHelpers';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -48,10 +47,6 @@ export default {
|
|||||||
if (this.options.host) return `${this.options.host}/api/v1/checks`;
|
if (this.options.host) return `${this.options.host}/api/v1/checks`;
|
||||||
return `${widgetApiEndpoints.healthChecks}`;
|
return `${widgetApiEndpoints.healthChecks}`;
|
||||||
},
|
},
|
||||||
proxyReqEndpoint() {
|
|
||||||
const baseUrl = process.env.VUE_APP_DOMAIN || window.location.origin;
|
|
||||||
return `${baseUrl}${serviceEndpoints.corsProxy}`;
|
|
||||||
},
|
|
||||||
apiKey() {
|
apiKey() {
|
||||||
if (!this.options.apiKey) {
|
if (!this.options.apiKey) {
|
||||||
this.error('An API key is required, please see the docs for more info');
|
this.error('An API key is required, please see the docs for more info');
|
||||||
@ -62,23 +57,11 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
/* Make GET request to CoinGecko API endpoint */
|
/* Make GET request to CoinGecko API endpoint */
|
||||||
fetchData() {
|
fetchData() {
|
||||||
const requestConfig = {
|
this.overrideProxyChoice = true;
|
||||||
method: 'GET',
|
const authHeaders = { 'X-Api-Key': this.apiKey };
|
||||||
url: this.proxyReqEndpoint,
|
this.makeRequest(this.endpoint, authHeaders).then(
|
||||||
headers: {
|
(response) => { this.processData(response); },
|
||||||
'access-control-request-headers': '*',
|
);
|
||||||
'Target-URL': this.endpoint,
|
|
||||||
CustomHeaders: JSON.stringify({ 'X-Api-Key': this.apiKey }),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
axios.request(requestConfig)
|
|
||||||
.then((response) => {
|
|
||||||
this.processData(response.data);
|
|
||||||
}).catch((error) => {
|
|
||||||
this.error('Unable to fetch cron data', error);
|
|
||||||
}).finally(() => {
|
|
||||||
this.finishLoading();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
/* Assign data variables to the returned data */
|
/* Assign data variables to the returned data */
|
||||||
processData(data) {
|
processData(data) {
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
|
||||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||||
import ChartingMixin from '@/mixins/ChartingMixin';
|
import ChartingMixin from '@/mixins/ChartingMixin';
|
||||||
|
|
||||||
@ -41,16 +40,9 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
/* Make GET request to NetData */
|
/* Make GET request to NetData */
|
||||||
fetchData() {
|
fetchData() {
|
||||||
axios.get(this.endpoint)
|
this.makeRequest(this.endpoint).then(
|
||||||
.then((response) => {
|
(response) => { this.processData(response); },
|
||||||
this.processData(response.data);
|
);
|
||||||
})
|
|
||||||
.catch((dataFetchError) => {
|
|
||||||
this.error('Unable to fetch data', dataFetchError);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.finishLoading();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
/* Assign data variables to the returned data */
|
/* Assign data variables to the returned data */
|
||||||
processData(data) {
|
processData(data) {
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
|
||||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||||
import ChartingMixin from '@/mixins/ChartingMixin';
|
import ChartingMixin from '@/mixins/ChartingMixin';
|
||||||
|
|
||||||
@ -41,16 +40,9 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
/* Make GET request to NetData */
|
/* Make GET request to NetData */
|
||||||
fetchData() {
|
fetchData() {
|
||||||
axios.get(this.endpoint)
|
this.makeRequest(this.endpoint).then(
|
||||||
.then((response) => {
|
(response) => { this.processData(response); },
|
||||||
this.processData(response.data);
|
);
|
||||||
})
|
|
||||||
.catch((dataFetchError) => {
|
|
||||||
this.error('Unable to fetch data', dataFetchError);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.finishLoading();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
/* Assign data variables to the returned data */
|
/* Assign data variables to the returned data */
|
||||||
processData(data) {
|
processData(data) {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios';
|
|
||||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||||
import ChartingMixin from '@/mixins/ChartingMixin';
|
import ChartingMixin from '@/mixins/ChartingMixin';
|
||||||
|
|
||||||
@ -37,16 +36,9 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
/* Make GET request to NetData */
|
/* Make GET request to NetData */
|
||||||
fetchData() {
|
fetchData() {
|
||||||
axios.get(this.endpoint)
|
this.makeRequest(this.endpoint).then(
|
||||||
.then((response) => {
|
(response) => { this.processData(response); },
|
||||||
this.processData(response.data);
|
);
|
||||||
})
|
|
||||||
.catch((dataFetchError) => {
|
|
||||||
this.error('Unable to fetch data', dataFetchError);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.finishLoading();
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
/* Assign data variables to the returned data */
|
/* Assign data variables to the returned data */
|
||||||
processData(inputData) {
|
processData(inputData) {
|
||||||
|
Loading…
Reference in New Issue
Block a user