Compare commits
2 Commits
202959dd9e
...
b0d66c9aa0
| Author | SHA1 | Date | |
|---|---|---|---|
| b0d66c9aa0 | |||
| 6b23bfb39f |
@@ -1,19 +1,19 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
: "${API_BASE_URL:=http://localhost}"
|
: "${API_HOST:=http://localhost}"
|
||||||
: "${API_PORT:=7070}"
|
: "${API_PORT:=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__ = {
|
||||||
API_BASE_URL: "${API_BASE_URL}",
|
API_HOST: "${API_HOST}",
|
||||||
API_PORT: "${API_PORT}"
|
API_PORT: "${API_PORT}"
|
||||||
};
|
};
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Generate nginx config from template (if using)
|
# Generate nginx config from template (if using)
|
||||||
if [ -f "/etc/nginx/templates/nginx.conf.template" ]; then
|
if [ -f "/etc/nginx/templates/nginx.conf.template" ]; then
|
||||||
envsubst '${API_BASE_URL} ${API_PORT}' \
|
envsubst '${API_HOST} ${API_PORT}' \
|
||||||
< /etc/nginx/templates/nginx.conf.template \
|
< /etc/nginx/templates/nginx.conf.template \
|
||||||
> /etc/nginx/nginx.conf
|
> /etc/nginx/nginx.conf
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ http {
|
|||||||
resolver 127.0.0.11 valid=10s ipv6=off;
|
resolver 127.0.0.11 valid=10s ipv6=off;
|
||||||
|
|
||||||
upstream backend {
|
upstream backend {
|
||||||
server ${API_BASE_URL}:${API_PORT};
|
server ${API_HOST}:${API_PORT};
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dex-ui-vue",
|
"name": "dex-ui-vue",
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "dex-ui-vue",
|
"name": "dex-ui-vue",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
window.__RUNTIME_CONFIG__ = {
|
window.__RUNTIME_CONFIG__ = {
|
||||||
API_BASE_URL: "__API_BASE_URL__",
|
API_HOST: "__API_HOST__",
|
||||||
API_PORT: "__API_PORT__"
|
API_PORT: "__API_PORT__"
|
||||||
};
|
};
|
||||||
10
src/main.ts
10
src/main.ts
@@ -139,8 +139,16 @@ router.beforeEach(async (to) => {
|
|||||||
app.use(router);
|
app.use(router);
|
||||||
app.use(ToastService)
|
app.use(ToastService)
|
||||||
|
|
||||||
|
let apiUrl = getApiUrl();
|
||||||
|
|
||||||
|
if (!apiUrl) {
|
||||||
|
apiUrl = `http://${apiUrl}`
|
||||||
|
} else {
|
||||||
|
apiUrl = ''
|
||||||
|
}
|
||||||
|
|
||||||
const axiosInstance = axios.create({
|
const axiosInstance = axios.create({
|
||||||
baseURL: getApiUrl() ?? '',
|
baseURL: apiUrl,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
export interface AppConfig {
|
export interface AppConfig {
|
||||||
API_BASE_URL: string;
|
API_HOST: string;
|
||||||
API_PORT: number;
|
API_PORT: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
let runtimeConfig: AppConfig = {
|
let runtimeConfig: AppConfig = {
|
||||||
API_BASE_URL: import.meta.env.VITE_API_BASE_URL || '',
|
API_HOST: import.meta.env.VITE_API_HOST || '',
|
||||||
API_PORT: import.meta.env.VITE_API_BASE_URL || 8080
|
API_PORT: import.meta.env.VITE_API_PORT || 8080
|
||||||
};
|
};
|
||||||
|
|
||||||
export function initConfig(config: Partial<AppConfig>) {
|
export function initConfig(config: Partial<AppConfig>) {
|
||||||
@@ -20,8 +20,8 @@ export function getConfig(): AppConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getApiUrl() {
|
export function getApiUrl() {
|
||||||
if (!runtimeConfig.API_BASE_URL) {
|
if (!runtimeConfig.API_HOST) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return `${runtimeConfig.API_BASE_URL}:${runtimeConfig.API_PORT}`;
|
return `${runtimeConfig.API_HOST}:${runtimeConfig.API_PORT}`;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user