Skip to content

Commit 377a09e

Browse files
authored
Merge pull request #853 from amoutaux/add-env-var-for-backend
feat(web): allow to configure proxy port through env var
2 parents b25e002 + f2ac7a1 commit 377a09e

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

web/vite.config.ts

+31-28
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
import { defineConfig } from 'vite'
1+
import { defineConfig, loadEnv } from 'vite'
22
import react from '@vitejs/plugin-react-swc'
33

44
// https://vitejs.dev/config/
5-
export default defineConfig({
6-
base: '/',
7-
plugins: [react()],
8-
assetsInclude: ['**/*.md'],
9-
server: {
10-
port: 8080,
11-
proxy: {
12-
"/api": {
13-
target: "http://localhost:5000",
14-
changeOrigin: true,
15-
secure: false,
16-
},
17-
"/doc": {
18-
target: "http://localhost:5000",
19-
changeOrigin: true,
20-
secure: false,
5+
export default defineConfig(({ mode }) => {
6+
const env = loadEnv(mode, process.cwd())
7+
return {
8+
base: '/',
9+
plugins: [react()],
10+
assetsInclude: ['**/*.md'],
11+
server: {
12+
port: 8080,
13+
proxy: {
14+
'/api': {
15+
target: 'http://localhost:' + `${env.VITE_PROXY_PORT ?? '5000'}`,
16+
changeOrigin: true,
17+
secure: false
18+
},
19+
'/doc': {
20+
target: 'http://localhost:' + `${env.VITE_PROXY_PORT ?? '5000'}`,
21+
changeOrigin: true,
22+
secure: false
23+
}
24+
}
25+
},
26+
test: {
27+
globals: true,
28+
environment: 'jsdom',
29+
css: true,
30+
reporters: ['verbose'],
31+
coverage: {
32+
reporter: ['text', 'json', 'html'],
33+
include: ['src/**/*'],
34+
exclude: []
2135
}
22-
}
23-
},
24-
test: {
25-
globals: true,
26-
environment: 'jsdom',
27-
css: true,
28-
reporters: ['verbose'],
29-
coverage: {
30-
reporter: ['text', 'json', 'html'],
31-
include: ['src/**/*'],
32-
exclude: [],
3336
}
3437
}
3538
})

0 commit comments

Comments
 (0)