add Pinia axios and VITE config to frontend.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
const env = (key: string): string => {
|
||||
const value = import.meta.env[key];
|
||||
if (value === undefined || value === null) {
|
||||
return '';
|
||||
}
|
||||
return String(value);
|
||||
};
|
||||
|
||||
const envInt = (key: string, fallback: number): number => {
|
||||
const raw = env(key);
|
||||
if (!raw) {
|
||||
return fallback;
|
||||
}
|
||||
const parsed = parseInt(raw, 10);
|
||||
return Number.isFinite(parsed) ? parsed : fallback;
|
||||
};
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
baseUrl: env('VITE_API_BASE_URL')
|
||||
},
|
||||
share: {
|
||||
clearnetDomain: env('VITE_CLEARNET_DOMAIN'),
|
||||
onionHostname: env('VITE_ONION_HOSTNAME')
|
||||
},
|
||||
limits: {
|
||||
maxImagesPerUpload: envInt('VITE_MAX_IMAGES_PER_UPLOAD', 10)
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
import axios from 'axios';
|
||||
import { config } from '@/config';
|
||||
|
||||
export const api = axios.create({
|
||||
baseURL: config.api.baseUrl,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
@@ -1,6 +1,9 @@
|
||||
import { createApp } from 'vue';
|
||||
import { createPinia } from 'pinia';
|
||||
import '@/assets/css/main.css';
|
||||
import App from './App.vue';
|
||||
import router from './router';
|
||||
|
||||
createApp(App).use(router).mount('#app');
|
||||
const pinia = createPinia();
|
||||
|
||||
createApp(App).use(pinia).use(router).mount('#app');
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import axios from 'axios';
|
||||
|
||||
export function resolveAxiosErrorMessage(error: unknown, fallback = 'Request failed'): string {
|
||||
if (axios.isAxiosError(error)) {
|
||||
const data = error.response?.data;
|
||||
if (typeof data === 'object' && data !== null && 'message' in data) {
|
||||
const message = (data as { message: unknown }).message;
|
||||
if (typeof message === 'string') {
|
||||
return message;
|
||||
}
|
||||
if (Array.isArray(message)) {
|
||||
return message.map(String).join(', ');
|
||||
}
|
||||
}
|
||||
if (error.message) {
|
||||
return error.message;
|
||||
}
|
||||
}
|
||||
if (error instanceof Error) {
|
||||
return error.message;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
Vendored
+11
@@ -1 +1,12 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
interface ImportMetaEnv {
|
||||
readonly VITE_API_BASE_URL: string;
|
||||
readonly VITE_CLEARNET_DOMAIN: string;
|
||||
readonly VITE_ONION_HOSTNAME: string;
|
||||
readonly VITE_MAX_IMAGES_PER_UPLOAD: string;
|
||||
}
|
||||
|
||||
interface ImportMeta {
|
||||
readonly env: ImportMetaEnv;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user