Skip to content

Commit

Permalink
frontend生产环境添加后端代理配置
Browse files Browse the repository at this point in the history
  • Loading branch information
Val-istar-Guo committed Mar 25, 2024
1 parent 9905c8b commit 9b3ec4b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
15 changes: 1 addition & 14 deletions app/frontend/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@
import { request } from 'keq'
const config = useRuntimeConfig()
if (process.server) {
if (config.apiBaseOrigin) {
request.baseOrigin(config.apiBaseOrigin)
request
.useRouter()
// eslint-disable-next-line @typescript-eslint/no-unused-vars
.module('backend', async (ctx, next) => {
try {
await next()
} catch (e) {
/* eslint-disable-next-line no-console */
console.log(e)
throw e
}
})
}
</script>
1 change: 1 addition & 0 deletions app/frontend/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM ghcr.io/buka-lnc/nodejs-slim:18 as builder

ARG PORT=80
ARG API_BASE_ORIGIN=http://backend-svc
ARG BACKEND_HOST=localhost:8080

COPY . /repo
WORKDIR /repo
Expand Down
9 changes: 5 additions & 4 deletions app/frontend/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import plugin from 'tailwindcss/plugin'
import themes from 'daisyui/src/theming/themes'
import colors from 'tailwindcss/colors'

const backendHost = process.env.BACKEND_HOST || 'localhost:8080'

export default defineNuxtConfig({
devtools: { enabled: false },
app: {},
Expand All @@ -23,10 +25,9 @@ export default defineNuxtConfig({
],

nitro: {
devProxy: {
'/api': {
target: 'http://localhost:8080/api',
changeOrigin: false,
routeRules: {
'/api/**': {
proxy: `http://${backendHost}/api/**`,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ services:
image: ghcr.io/buka-lnc/opendoc-frontend:latest
ports:
- "3000:3000"
environment:
BACKEND_HOST: backend:8080
backend:
image: ghcr.io/buka-lnc/opendoc-backend:latest
ports:
Expand Down

0 comments on commit 9b3ec4b

Please sign in to comment.