Skip to content

Commit

Permalink
chore(refactor): move apiUrl to composable
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Mar 19, 2024
1 parent 309630a commit 0189a1e
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 21 deletions.
9 changes: 6 additions & 3 deletions components/community/Community.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
import SourcePull from "vue-material-design-icons/SourcePull.vue";
import BugOutline from "vue-material-design-icons/BugOutline.vue";
import AccountGroupOutline from "vue-material-design-icons/AccountGroupOutline.vue";
import {kestraInstance} from "~/utils/api.js";
import {useApi} from "~/composables/useApi.js";
export default {
components: {
Expand All @@ -114,6 +114,9 @@
BugOutline,
AccountGroupOutline,
},
setup() {
return {useApi}
},
data() {
return {
metrics: undefined,
Expand All @@ -123,8 +126,8 @@
async created() {
try {
const [metrics, contributors] = await Promise.all([
kestraInstance.get('/communities/github/metrics'),
kestraInstance.get('/communities/github/contributors')
this.useApi.get('/communities/github/metrics'),
this.useApi.get('/communities/github/contributors')
])
this.metrics = metrics.data
this.contributors = contributors.data
Expand Down
7 changes: 5 additions & 2 deletions components/community/Contributors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

<script>
import Section from '../../components/layout/Section.vue';
import { kestraInstance } from "~/utils/api.js";
import {useApi} from "~/composables/useApi.js";
export default {
components: {Section},
setup() {
return {useApi}
},
data() {
return {
contributors: undefined,
Expand All @@ -33,7 +36,7 @@
},
async created() {
try {
const { data } = await kestraInstance.get('/communities/github/contributors')
const { data } = await this.useApi.get('/communities/github/contributors')
this.contributors = data
this.contributorsRand = this.contributors.sort(() => 0.5 - Math.random())
} catch (e) {
Expand Down
7 changes: 5 additions & 2 deletions components/community/Slack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@
import Section from '../../components/layout/Section.vue';
import Card from '../card/Card.vue';
import Slack from "vue-material-design-icons/Slack.vue";
import { kestraInstance } from "~/utils/api.js";
import {useApi} from "~/composables/useApi.js";
export default {
components: {Slack, Section, Card},
setup() {
return {useApi}
},
props: {
widget: {
type: Boolean,
Expand All @@ -75,7 +78,7 @@ export default {
const memberCount = window.sessionStorage.getItem("slack_member_count")
if (!memberCount) {
const { data: { total } } = await kestraInstance.get('/communities/slack')
const { data: { total } } = await this.useApi.get('/communities/slack')
window.sessionStorage.setItem("slack_member_count", total)
this.online = total
} else {
Expand Down
9 changes: 6 additions & 3 deletions components/home/OpenSource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
import SourcePull from "vue-material-design-icons/SourcePull.vue";
import BugOutline from "vue-material-design-icons/BugOutline.vue";
import AccountGroupOutline from "vue-material-design-icons/AccountGroupOutline.vue";
import {kestraInstance} from "~/utils/api.js";
import {useApi} from "~/composables/useApi.js";
export default {
components: {
Expand All @@ -92,6 +92,9 @@
Section,
CountTo
},
setup() {
return {useApi}
},
data() {
return {
contributors: undefined,
Expand All @@ -104,8 +107,8 @@
async created() {
try {
const [metrics, contributors] = await Promise.all([
kestraInstance.get('/communities/github/metrics'),
kestraInstance.get('/communities/github/contributors')
this.useApi.get('/communities/github/metrics'),
this.useApi.get('/communities/github/contributors')
])
this.metrics = metrics.data
this.contributors = contributors.data
Expand Down
9 changes: 9 additions & 0 deletions composables/useApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import axios from 'axios'

export const useApi = () => {
const runtimeConfig = useRuntimeConfig()

return axios.create({
baseURL: runtimeConfig.public.apiUrl
})
};
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const DEFAULT_KESTRA_API_URL = 'https://api.kestra.io/v1';
const DEFAULT_KESTRA_API_URL = 'https://api.develop.kestra.io/v1';
export default defineNuxtConfig({
modules: [
'@nuxt/devtools',
Expand Down
3 changes: 2 additions & 1 deletion plugins/cookieconsent.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import axios from "axios";

export default defineNuxtPlugin(nuxtApp => {
const isEurope = Intl.DateTimeFormat().resolvedOptions().timeZone.indexOf("Europe") === 0;
const runtimeConfig = useRuntimeConfig()
const cookieConsent = CookieConsent;
nuxtApp.provide("cookieConsent", cookieConsent);

Expand All @@ -13,7 +14,7 @@ export default defineNuxtPlugin(nuxtApp => {
const enabledAnalytics = async () => {
initialize();

const response = await axios.get('https://api.kestra.io/v1/config', {withCredentials: true})
const response = await axios.get(`${runtimeConfig.public.apiUrl}/config`, {withCredentials: true})

posthog.init(
response.data.posthog.token,
Expand Down
6 changes: 4 additions & 2 deletions server/api/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import {recursivePages} from "~/utils/navigation.js";
import type {SitemapUrlInput} from "@nuxtjs/sitemap/dist/runtime/types";

const generateDefaultSitemap = async () => {
const runtimeConfig = useRuntimeConfig()

type SitemapsToGenerate = { rootUrl: string, apiUrl: string, sitemap?: string };
const sitemapsToGenerate: Array<SitemapsToGenerate> = [
{
rootUrl: '/blueprints/',
apiUrl: 'https://api.kestra.io/v1/blueprints',
apiUrl: `${runtimeConfig.public.apiUrl}/blueprints`,
},
{
rootUrl: '/use-cases/stories/',
apiUrl: 'https://api.kestra.io/v1/customer-stories'
apiUrl: `${runtimeConfig.public.apiUrl}/customer-stories`
}
];

Expand Down
7 changes: 0 additions & 7 deletions utils/api.js

This file was deleted.

0 comments on commit 0189a1e

Please sign in to comment.