This commit is contained in:
@@ -2,10 +2,9 @@
|
|||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { GetUser, LogoutUser } from '@/services/User'
|
import { GetUser, LogoutUser } from '@/services/User'
|
||||||
|
|
||||||
import Server from '@/services/Server'
|
import Server, { getBaseUrl } from '@/services/Server'
|
||||||
|
|
||||||
import { CreateWindow, CreateChildWindow, ClearWindow, GetFirstWindowId } from '../../services/Windows';
|
import { CreateWindow, CreateChildWindow, ClearWindow, GetFirstWindowId } from '../../services/Windows';
|
||||||
import { backendUrl } from '../../services/BackendURL';
|
|
||||||
import Spinner from './Spinner.vue';
|
import Spinner from './Spinner.vue';
|
||||||
const loadedIcon = ref(false);
|
const loadedIcon = ref(false);
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ function retrieveAvatar(){
|
|||||||
Server().get('/user/retrieve-avatar?username=' + GetUser().username)
|
Server().get('/user/retrieve-avatar?username=' + GetUser().username)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if(response.data.image){
|
if(response.data.image){
|
||||||
const imgUrl = backendUrl + "/public/" + response.data.image;
|
const imgUrl = getBaseUrl() + "/public/" + response.data.image;
|
||||||
|
|
||||||
// Wait for the image to fully load
|
// Wait for the image to fully load
|
||||||
const img = new Image();
|
const img = new Image();
|
||||||
|
|||||||
6
frontend/app/plugins/api.ts
Normal file
6
frontend/app/plugins/api.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { initApi } from '../services/Server';
|
||||||
|
|
||||||
|
export default defineNuxtPlugin(() => {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
initApi(config.public.apiBaseUrl);
|
||||||
|
});
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
const backendUrl = import.meta.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:5000/api'
|
|
||||||
|
|
||||||
export {
|
|
||||||
backendUrl
|
|
||||||
};
|
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
const server = axios.create({
|
const server = axios.create({
|
||||||
baseURL: import.meta.env.NUXT_PUBLIC_API_BASE_URL || 'http://localhost:5000/api',
|
baseURL: 'http://localhost:5000/api', // fallback only
|
||||||
headers: {
|
headers: {
|
||||||
"Access-Control-Allow-Origin": "*",
|
"Access-Control-Allow-Origin": "*",
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Attach token dynamically on each request via interceptor
|
export const initApi = (baseURL: string) => {
|
||||||
|
server.defaults.baseURL = baseURL;
|
||||||
|
};
|
||||||
|
|
||||||
server.interceptors.request.use((config) => {
|
server.interceptors.request.use((config) => {
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
if (token) {
|
if (token) {
|
||||||
@@ -17,3 +20,5 @@ server.interceptors.request.use((config) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default () => server;
|
export default () => server;
|
||||||
|
|
||||||
|
export const getBaseUrl = () => server.defaults.baseURL;
|
||||||
Reference in New Issue
Block a user