mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-25 07:00:48 +09:00
fix(deploy): vite config lazy load
This commit is contained in:
+2
-2
@@ -114,8 +114,8 @@ services:
|
|||||||
context: .
|
context: .
|
||||||
dockerfile: docker/Dockerfile.web
|
dockerfile: docker/Dockerfile.web
|
||||||
args:
|
args:
|
||||||
- VITE_API_URL=http://localhost:8080
|
- VITE_API_URL=${VITE_API_URL:-http://localhost:8080}
|
||||||
- VITE_AGENT_URL=http://localhost:8081
|
- VITE_AGENT_URL=${VITE_AGENT_URL:-http://localhost:8081}
|
||||||
container_name: memoh-web
|
container_name: memoh-web
|
||||||
ports:
|
ports:
|
||||||
- "8082:8082"
|
- "8082:8082"
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ RUN apk add --no-cache ca-certificates wget
|
|||||||
COPY --from=builder /build/agent/dist /app/dist
|
COPY --from=builder /build/agent/dist /app/dist
|
||||||
COPY --from=builder /build/agent/node_modules /app/node_modules
|
COPY --from=builder /build/agent/node_modules /app/node_modules
|
||||||
COPY --from=builder /build/agent/package.json /app/package.json
|
COPY --from=builder /build/agent/package.json /app/package.json
|
||||||
|
COPY --from=builder /build/node_modules /node_modules
|
||||||
|
|
||||||
EXPOSE 8081
|
EXPOSE 8081
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ WORKDIR /build
|
|||||||
RUN npm install -g pnpm@10
|
RUN npm install -g pnpm@10
|
||||||
|
|
||||||
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
|
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
|
||||||
COPY config.toml ./
|
|
||||||
|
|
||||||
COPY packages ./packages
|
COPY packages ./packages
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,11 @@ import router from '@/router'
|
|||||||
* Call this once at app startup (main.ts).
|
* Call this once at app startup (main.ts).
|
||||||
*/
|
*/
|
||||||
export function setupApiClient() {
|
export function setupApiClient() {
|
||||||
// Set base URL to match the Vite proxy
|
const apiBaseUrl = import.meta.env.VITE_API_URL?.trim() || '/api'
|
||||||
client.setConfig({ baseUrl: '/api' })
|
const agentBaseUrl = import.meta.env.VITE_AGENT_URL?.trim() || '/agent'
|
||||||
|
void agentBaseUrl
|
||||||
|
|
||||||
|
client.setConfig({ baseUrl: apiBaseUrl })
|
||||||
|
|
||||||
// Add auth token to every request
|
// Add auth token to every request
|
||||||
client.interceptors.request.use((request) => {
|
client.interceptors.request.use((request) => {
|
||||||
|
|||||||
+61
-32
@@ -1,43 +1,72 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import tailwindcss from '@tailwindcss/vite'
|
import tailwindcss from '@tailwindcss/vite'
|
||||||
|
import { createRequire } from 'module'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'url'
|
||||||
import { loadConfig, getBaseUrl } from '@memoh/config'
|
|
||||||
|
|
||||||
const config = loadConfig('../../config.toml')
|
|
||||||
const { web: { port = 8082, host = '127.0.0.1' } } = config
|
|
||||||
const baseUrl = getBaseUrl(config)
|
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig(({ command }) => {
|
||||||
plugins: [vue(), tailwindcss()],
|
const require = createRequire(import.meta.url)
|
||||||
server: {
|
const defaultPort = 8082
|
||||||
port,
|
const defaultHost = '127.0.0.1'
|
||||||
host,
|
const defaultApiBaseUrl = process.env.VITE_API_URL ?? 'http://localhost:8080'
|
||||||
proxy: {
|
|
||||||
'/api': {
|
let port = defaultPort
|
||||||
target: baseUrl,
|
let host = defaultHost
|
||||||
changeOrigin: true,
|
let baseUrl = defaultApiBaseUrl
|
||||||
rewrite: (path) => path.replace(/^\/api/, '')
|
|
||||||
|
if (command !== 'build') {
|
||||||
|
try {
|
||||||
|
const { loadConfig, getBaseUrl } = require('@memoh/config') as {
|
||||||
|
loadConfig: (path: string) => {
|
||||||
|
web?: { port?: number; host?: string }
|
||||||
|
}
|
||||||
|
getBaseUrl: (config: unknown) => string
|
||||||
}
|
}
|
||||||
},
|
let config
|
||||||
},
|
try {
|
||||||
preview: {
|
config = loadConfig('../../config.toml')
|
||||||
port,
|
} catch {
|
||||||
host: '0.0.0.0',
|
config = loadConfig('../../docker/config/config.docker.toml')
|
||||||
proxy: {
|
|
||||||
'/api': {
|
|
||||||
target: baseUrl,
|
|
||||||
changeOrigin: true,
|
|
||||||
rewrite: (path) => path.replace(/^\/api/, '')
|
|
||||||
}
|
}
|
||||||
|
port = config.web?.port ?? defaultPort
|
||||||
|
host = config.web?.host ?? defaultHost
|
||||||
|
baseUrl = getBaseUrl(config)
|
||||||
|
} catch {
|
||||||
|
// Fall back to env/default values when config.toml is unavailable.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
plugins: [vue(), tailwindcss()],
|
||||||
|
server: {
|
||||||
|
port,
|
||||||
|
host,
|
||||||
|
proxy: {
|
||||||
|
'/api': {
|
||||||
|
target: baseUrl,
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (path: string) => path.replace(/^\/api/, '')
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
allowedHosts: true,
|
preview: {
|
||||||
},
|
port,
|
||||||
resolve: {
|
host: '0.0.0.0',
|
||||||
alias: {
|
proxy: {
|
||||||
'#': fileURLToPath(new URL('../ui/src', import.meta.url)),
|
'/api': {
|
||||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
target: baseUrl,
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: (path: string) => path.replace(/^\/api/, '')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
allowedHosts: true,
|
||||||
},
|
},
|
||||||
},
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
'#': fileURLToPath(new URL('../ui/src', import.meta.url)),
|
||||||
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user