Amend CORS and NGINX
This commit is contained in:
@@ -7,7 +7,7 @@ COPY . .
|
|||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Stage 2: Create runtime image
|
# Stage 2: Create runtime image
|
||||||
FROM nginxinc/nginx-unprivileged:1.25-alpine
|
FROM nginxinc/nginx-unprivileged:1.25-alpine AS runtime
|
||||||
|
|
||||||
# Create writable directories
|
# Create writable directories
|
||||||
USER root
|
USER root
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
: "${API_BASE_URL:=http://localhost:7070}"
|
||||||
# Create runtime config file in writable location
|
# Create runtime config file in writable location
|
||||||
cat > /runtime-config/config.js <<EOF
|
cat > /runtime-config/config.js <<EOF
|
||||||
window.__APP_CONFIG__ = {
|
window.__APP_CONFIG__ = {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ http {
|
|||||||
}
|
}
|
||||||
|
|
||||||
upstream backend {
|
upstream backend {
|
||||||
server localhost:8080;
|
server ${API_BASE_URL}:8080;
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
@@ -54,9 +54,9 @@ http {
|
|||||||
access_log off;
|
access_log off;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /api/ {
|
location ^~ /api/ {
|
||||||
# Proxy to Quarkus
|
# Proxy to Quarkus
|
||||||
proxy_pass http://backend/;
|
proxy_pass http://backend;
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
window.__RUNTIME_CONFIG__ = {
|
window.__RUNTIME_CONFIG__ = {
|
||||||
API_URL: "__API_URL__"
|
API_BASE_URL: "__API_BASE_URL__"
|
||||||
};
|
};
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import axios from "axios";
|
|
||||||
import {userManager} from "../stores/auth.ts";
|
|
||||||
import {getConfig} from "@/util/config.ts";
|
|
||||||
|
|
||||||
const axiosInstance = axios.create({
|
|
||||||
baseURL: getConfig().API_BASE_URL || '/api',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
axiosInstance.interceptors.request.use(async (config) => {
|
|
||||||
const user = await userManager.getUser()
|
|
||||||
if (user?.access_token) {
|
|
||||||
config.headers.Authorization = `Bearer ${user.access_token}`
|
|
||||||
}
|
|
||||||
return config
|
|
||||||
})
|
|
||||||
|
|
||||||
// Handle token expiration
|
|
||||||
axiosInstance.interceptors.response.use(
|
|
||||||
response => response,
|
|
||||||
async (error) => {
|
|
||||||
if (error.response?.status === 401) {
|
|
||||||
await userManager.signinRedirect()
|
|
||||||
}
|
|
||||||
return Promise.reject(error)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
export default axiosInstance;
|
|
||||||
46
src/main.ts
46
src/main.ts
@@ -23,11 +23,11 @@ import DecksView from "./views/deck/DecksView.vue";
|
|||||||
import DeckView from "./views/deck/DeckView.vue";
|
import DeckView from "./views/deck/DeckView.vue";
|
||||||
import Callback from "./views/Callback.vue";
|
import Callback from "./views/Callback.vue";
|
||||||
import {useAuthStore} from "./stores/auth.ts";
|
import {useAuthStore} from "./stores/auth.ts";
|
||||||
import axiosInstance from "./api";
|
|
||||||
import SetsView from "./views/set/SetsView.vue";
|
import SetsView from "./views/set/SetsView.vue";
|
||||||
import JobsView from "./views/JobsView.vue";
|
import JobsView from "./views/JobsView.vue";
|
||||||
import {definePreset} from "@primeuix/themes";
|
import {definePreset} from "@primeuix/themes";
|
||||||
import {initConfig} from "@/util/config.ts";
|
import {getConfig, initConfig} from "@/util/config.ts";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
// Initialize configuration from window object
|
// Initialize configuration from window object
|
||||||
initConfig((window as any).__APP_CONFIG__ || {})
|
initConfig((window as any).__APP_CONFIG__ || {})
|
||||||
@@ -139,11 +139,43 @@ router.beforeEach(async (to) => {
|
|||||||
app.use(router);
|
app.use(router);
|
||||||
app.use(ToastService)
|
app.use(ToastService)
|
||||||
|
|
||||||
const deckService: DeckService = new DeckService(undefined, "/api", axiosInstance)
|
console.log(getConfig().API_BASE_URL)
|
||||||
const cardService: CardService = new CardService(undefined, "/api", axiosInstance)
|
|
||||||
const setService: SetService = new SetService(undefined, "/api", axiosInstance)
|
const axiosInstance = axios.create({
|
||||||
const cardPrintService: CardPrintService = new CardPrintService(undefined, "/api", axiosInstance)
|
baseURL: getConfig().API_BASE_URL ?? '',
|
||||||
const jobService: JobService = new JobService(undefined, "/api", axiosInstance)
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
axiosInstance.interceptors.request.use(async (config) => {
|
||||||
|
const user = await userManager.getUser()
|
||||||
|
if (user?.access_token) {
|
||||||
|
config.headers.Authorization = `Bearer ${user.access_token}`
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
})
|
||||||
|
|
||||||
|
// Handle token expiration
|
||||||
|
axiosInstance.interceptors.response.use(
|
||||||
|
response => response,
|
||||||
|
async (error) => {
|
||||||
|
if (error.response?.status === 401) {
|
||||||
|
await userManager.signinRedirect()
|
||||||
|
}
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const deckService: DeckService = new DeckService(undefined, undefined, axiosInstance)
|
||||||
|
const cardService: CardService = new CardService(undefined, undefined, axiosInstance)
|
||||||
|
const setService: SetService = new SetService(undefined, undefined, axiosInstance)
|
||||||
|
const cardPrintService: CardPrintService = new CardPrintService(undefined, undefined, axiosInstance)
|
||||||
|
const jobService: JobService = new JobService(undefined, undefined, axiosInstance)
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
console.log(deckService.basePath)
|
||||||
|
console.log(axiosInstance.defaults.baseURL)
|
||||||
|
|
||||||
app.provide(DeckServiceKey, deckService)
|
app.provide(DeckServiceKey, deckService)
|
||||||
app.provide(CardServiceKey, cardService)
|
app.provide(CardServiceKey, cardService)
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
export interface AppConfig {
|
export interface AppConfig {
|
||||||
API_BASE_URL: string;
|
API_BASE_URL: string;
|
||||||
OTHER_VAR: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let runtimeConfig: AppConfig = {
|
let runtimeConfig: AppConfig = {
|
||||||
API_BASE_URL: import.meta.env.VITE_API_BASE_URL || '',
|
API_BASE_URL: import.meta.env.VITE_API_BASE_URL || ''
|
||||||
OTHER_VAR: import.meta.env.VITE_OTHER_VAR || ''
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function initConfig(config: Partial<AppConfig>) {
|
export function initConfig(config: Partial<AppConfig>) {
|
||||||
|
|||||||
Reference in New Issue
Block a user