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: .
|
||||
dockerfile: docker/Dockerfile.web
|
||||
args:
|
||||
- VITE_API_URL=http://localhost:8080
|
||||
- VITE_AGENT_URL=http://localhost:8081
|
||||
- VITE_API_URL=${VITE_API_URL:-http://localhost:8080}
|
||||
- VITE_AGENT_URL=${VITE_AGENT_URL:-http://localhost:8081}
|
||||
container_name: memoh-web
|
||||
ports:
|
||||
- "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/node_modules /app/node_modules
|
||||
COPY --from=builder /build/agent/package.json /app/package.json
|
||||
COPY --from=builder /build/node_modules /node_modules
|
||||
|
||||
EXPOSE 8081
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ WORKDIR /build
|
||||
RUN npm install -g pnpm@10
|
||||
|
||||
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml ./
|
||||
COPY config.toml ./
|
||||
|
||||
COPY packages ./packages
|
||||
|
||||
|
||||
@@ -6,8 +6,11 @@ import router from '@/router'
|
||||
* Call this once at app startup (main.ts).
|
||||
*/
|
||||
export function setupApiClient() {
|
||||
// Set base URL to match the Vite proxy
|
||||
client.setConfig({ baseUrl: '/api' })
|
||||
const apiBaseUrl = import.meta.env.VITE_API_URL?.trim() || '/api'
|
||||
const agentBaseUrl = import.meta.env.VITE_AGENT_URL?.trim() || '/agent'
|
||||
void agentBaseUrl
|
||||
|
||||
client.setConfig({ baseUrl: apiBaseUrl })
|
||||
|
||||
// Add auth token to every request
|
||||
client.interceptors.request.use((request) => {
|
||||
|
||||
+61
-32
@@ -1,43 +1,72 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
import { createRequire } from 'module'
|
||||
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/
|
||||
export default defineConfig({
|
||||
plugins: [vue(), tailwindcss()],
|
||||
server: {
|
||||
port,
|
||||
host,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: baseUrl,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, '')
|
||||
export default defineConfig(({ command }) => {
|
||||
const require = createRequire(import.meta.url)
|
||||
const defaultPort = 8082
|
||||
const defaultHost = '127.0.0.1'
|
||||
const defaultApiBaseUrl = process.env.VITE_API_URL ?? 'http://localhost:8080'
|
||||
|
||||
let port = defaultPort
|
||||
let host = defaultHost
|
||||
let baseUrl = defaultApiBaseUrl
|
||||
|
||||
if (command !== 'build') {
|
||||
try {
|
||||
const { loadConfig, getBaseUrl } = require('@memoh/config') as {
|
||||
loadConfig: (path: string) => {
|
||||
web?: { port?: number; host?: string }
|
||||
}
|
||||
getBaseUrl: (config: unknown) => string
|
||||
}
|
||||
},
|
||||
},
|
||||
preview: {
|
||||
port,
|
||||
host: '0.0.0.0',
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: baseUrl,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/api/, '')
|
||||
let config
|
||||
try {
|
||||
config = loadConfig('../../config.toml')
|
||||
} catch {
|
||||
config = loadConfig('../../docker/config/config.docker.toml')
|
||||
}
|
||||
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,
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'#': fileURLToPath(new URL('../ui/src', import.meta.url)),
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
preview: {
|
||||
port,
|
||||
host: '0.0.0.0',
|
||||
proxy: {
|
||||
'/api': {
|
||||
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