浏览代码

strapi url to .env

Benjamin Kornblum 5 月之前
父节点
当前提交
a4098ec238
共有 5 个文件被更改,包括 34 次插入37 次删除
  1. 1 0
      .env
  2. 9 13
      src/stores/component.ts
  3. 1 1
      src/stores/footer-content-pages.ts
  4. 14 14
      src/stores/pages.ts
  5. 9 9
      src/stores/timeline.ts

+ 1 - 0
.env

@@ -1,2 +1,3 @@
 VITE_STRAPI_TOKEN=c1f8dac9ec1b803aa0902dced56958c91115acbbc216832757f95457d25bde1682863bb6144d574297560f3139f0e8610d05509a4d37ec19b96d0366f4b3ccdd246c97cdff0d877eb12ec3272b58d3203fd050267c5d089b68b9e8198534d74ded49564a6a5bd64e3825b617b0f0a6fe07fdada4ae941f15b6b144abdc89d804
+VITE_STRAPI_URL=https://strapi.kornblum.one/api
 VITE_GOOGLE_MAPS_API_KEY=AIzaSyBZkPFVq8-Zm5xxMSRZWpB7D7n-O6exlKs

+ 9 - 13
src/stores/component.ts

@@ -2,34 +2,30 @@ import { defineStore } from 'pinia'
 import axios from 'axios'
 import type { Component } from '../types/component'
 
-
-
-
-
-export const useComponentStore = defineStore('components',{
+export const useComponentStore = defineStore('components', {
   state: () => ({
     components: [] as Array<Component>,
     locale: (localStorage.getItem('lang') || 'de')
   }),
   actions: {
-    async getComponents(locale: string){
+    async getComponents(locale: string) {
       await this.setLocale(locale)
       return this.components
 
     },
 
-    async setLocale(locale: string){
-      if(this.components.length == 0 || this.locale != locale ){
+    async setLocale(locale: string) {
+      if (this.components.length == 0 || this.locale != locale) {
         this.locale = locale
         await this.fetchComponents()
       }
     },
 
-    async fetchComponents(){
-      const response = await axios.get('https://strapi.kornblum.one/api/components?locale='+this.locale, {
-      headers: {
-          Authorization: "Bearer "+ import.meta.env.VITE_STRAPI_TOKEN,
-      },
+    async fetchComponents() {
+      const response = await axios.get(import.meta.env.VITE_STRAPI_URL + '/api/components?locale=' + this.locale, {
+        headers: {
+          Authorization: "Bearer " + import.meta.env.VITE_STRAPI_TOKEN,
+        },
       })
       this.components = response.data.data
     },

+ 1 - 1
src/stores/footer-content-pages.ts

@@ -27,7 +27,7 @@ export const useFooterLinksStore = defineStore('footerLinks', {
     },
 
     async fetchLinks() {
-      const response = await axios.get('https://strapi.kornblum.one/api/footer-content-pages?&populate[localizations][fields][0]=Label&populate[page][fields][1]=path&locale=' + this.locale, {
+      const response = await axios.get(import.meta.env.VITE_STRAPI_URL + '/footer-content-pages?&populate[localizations][fields][0]=Label&populate[page][fields][1]=path&locale=' + this.locale, {
         headers: {
           Authorization: "Bearer " + import.meta.env.VITE_STRAPI_TOKEN,
         },

+ 14 - 14
src/stores/pages.ts

@@ -3,29 +3,29 @@ import axios from 'axios'
 
 import type { Page } from '../types/page'
 
-export const usePageStore = defineStore('pages',{
+export const usePageStore = defineStore('pages', {
   state: () => ({
     locale: (localStorage.getItem('lang') || 'de'),
     pages: [] as Array<Page>
   }),
 
-   actions: {
-    getPageByTitle (title: string) {
+  actions: {
+    getPageByTitle(title: string) {
       return this.pages.find((page) => page.Title === title)
     },
-    async setLocale(locale: string){
-      if(this.pages.length == 0 || this.locale != locale ){
+    async setLocale(locale: string) {
+      if (this.pages.length == 0 || this.locale != locale) {
         this.locale = locale
         await this.fetchPages()
       }
     },
-    async fetchPages(){
-        const response = await axios.get('https://strapi.kornblum.one/api/pages?locale='+this.locale, {
-          headers: {
-            Authorization: "Bearer " + import.meta.env.VITE_STRAPI_TOKEN,
-          },
-        })
-        this.pages = response.data.data
+    async fetchPages() {
+      const response = await axios.get(import.meta.env.VITE_STRAPI_URL + '/pages?locale=' + this.locale, {
+        headers: {
+          Authorization: "Bearer " + import.meta.env.VITE_STRAPI_TOKEN,
+        },
+      })
+      this.pages = response.data.data
     }
-   }
- })
+  }
+})

+ 9 - 9
src/stores/timeline.ts

@@ -4,30 +4,30 @@ import axios from 'axios'
 import type { Timeline } from '../types/timeline'
 
 
-export const useTimelineStore = defineStore('timelines',{
+export const useTimelineStore = defineStore('timelines', {
   state: () => ({
     timelines: [] as Array<Timeline>,
     locale: (localStorage.getItem('lang') || 'de')
   }),
   actions: {
-    async getTimelines(locale: string){
+    async getTimelines(locale: string) {
       await this.setLocale(locale)
       return this.timelines
 
     },
 
-    async setLocale(locale: string){
-      if(this.timelines.length == 0 || this.locale != locale ){
+    async setLocale(locale: string) {
+      if (this.timelines.length == 0 || this.locale != locale) {
         this.locale = locale
         await this.fetchTimelines()
       }
     },
 
-    async fetchTimelines(){
-      const response = await axios.get('https://strapi.kornblum.one/api/timelines?sort=date&locale='+this.locale, {
-      headers: {
-          Authorization: "Bearer "+ import.meta.env.VITE_STRAPI_TOKEN,
-      },
+    async fetchTimelines() {
+      const response = await axios.get(import.meta.env.VITE_STRAPI_URL + '/timelines?sort=date&locale=' + this.locale, {
+        headers: {
+          Authorization: "Bearer " + import.meta.env.VITE_STRAPI_TOKEN,
+        },
       })
       this.timelines = response.data.data
     },