frontend: add config for endpoints
Signed-off-by: Nicolas Froger <nicolas@kektus.xyz>
This commit is contained in:
parent
ddc6c64f0f
commit
bfaa1c0014
7 changed files with 19 additions and 7 deletions
|
|
@ -1 +1,3 @@
|
|||
VUE_APP_API_BASEURL=http://localhost:8080
|
||||
VITE_API_BASEURL=http://localhost:8080
|
||||
VITE_S3_ENDPOINT=http://localhost:32771
|
||||
VITE_S3_BUCKET=assets
|
||||
|
|
|
|||
3
summer2024-frontend/.env.production
Normal file
3
summer2024-frontend/.env.production
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
VITE_API_BASEURL=https://api.summer2024.kektus.fr
|
||||
VITE_S3_ENDPOINT=https://s3.kektus.fr
|
||||
VITE_S3_BUCKET=kektus-summer2024-assets
|
||||
3
summer2024-frontend/src/config.js
Normal file
3
summer2024-frontend/src/config.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
export const API_BASE_URL = import.meta.env.VITE_API_BASEURL;
|
||||
export const S3_ENDPOINT = import.meta.env.VITE_S3_ENDPOINT;
|
||||
export const S3_BUCKET = import.meta.env.VITE_S3_BUCKET;
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { useAuthStore } from '@/stores/auth.js'
|
||||
import { API_BASE_URL } from '@/config.js'
|
||||
|
||||
export const useAdminPostsStore = defineStore("adminPosts", () => {
|
||||
const authStore = useAuthStore();
|
||||
|
|
@ -11,7 +12,7 @@ export const useAdminPostsStore = defineStore("adminPosts", () => {
|
|||
if (!authStore.isAuth)
|
||||
return
|
||||
|
||||
fetch("http://localhost:8080/admin/posts", {
|
||||
fetch(API_BASE_URL + "/admin/posts", {
|
||||
headers: {
|
||||
"X-admin-token": authStore.adminToken
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { API_BASE_URL } from '@/config.js'
|
||||
|
||||
export const useAuthStore = defineStore("auth", () => {
|
||||
const adminToken = ref("");
|
||||
|
|
@ -11,7 +12,7 @@ export const useAuthStore = defineStore("auth", () => {
|
|||
isAuth.value = false;
|
||||
error.value = false;
|
||||
|
||||
return fetch("http://localhost:8080/admin/auth/check", {
|
||||
return fetch(API_BASE_URL + "/admin/auth/check", {
|
||||
headers: {
|
||||
"X-admin-token": token
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ import { ref } from 'vue'
|
|||
import { formatRelative } from 'date-fns'
|
||||
import { fr } from 'date-fns/locale'
|
||||
import { marked } from 'marked'
|
||||
import { API_BASE_URL } from '@/config.js'
|
||||
|
||||
export const usePostsStore = defineStore('posts', () => {
|
||||
const postsApiPath = 'http://localhost:8080/posts'
|
||||
const postsApiPath = API_BASE_URL + '/posts'
|
||||
|
||||
const posts = ref([])
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import {
|
|||
import { Card, CardContent } from '@/components/ui/card/index.js'
|
||||
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert/index.js'
|
||||
import { useAuthStore } from '@/stores/auth.js'
|
||||
import { API_BASE_URL, S3_BUCKET, S3_ENDPOINT } from '@/config.js'
|
||||
|
||||
const authStore = useAuthStore();
|
||||
|
||||
|
|
@ -57,7 +58,7 @@ const onSubmit = form.handleSubmit(async (values) => {
|
|||
const assets = []
|
||||
for (const file of selectedFiles.value) {
|
||||
console.log('Contact API asset')
|
||||
const response = await fetch('http://localhost:8080/admin/assets', {
|
||||
const response = await fetch(API_BASE_URL + '/admin/assets', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
@ -84,7 +85,7 @@ const onSubmit = form.handleSubmit(async (values) => {
|
|||
mediaUploadFormData.append('file', file.file, responseBody.filename)
|
||||
|
||||
console.log('Envoi image sur s3')
|
||||
const s3Response = await fetch('http://localhost:32795/assets/', {
|
||||
const s3Response = await fetch(`${S3_ENDPOINT}/${S3_BUCKET}/`, {
|
||||
method: 'POST',
|
||||
body: mediaUploadFormData
|
||||
})
|
||||
|
|
@ -100,7 +101,7 @@ const onSubmit = form.handleSubmit(async (values) => {
|
|||
assets.push(responseBody.id)
|
||||
}
|
||||
|
||||
const response = await fetch('http://localhost:8080/admin/posts', {
|
||||
const response = await fetch(API_BASE_URL + '/admin/posts', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue