Skip to content

Commit

Permalink
fix: make proxy work as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed Nov 11, 2024
1 parent eaf99ae commit f298e08
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ const config = ({ mode }: { mode: string }): UserConfigExport => {
...loadEnv(mode, process.cwd()),
};

const { VITE_PORT, BROWSER, VITE_UMAMI_WEBSITE_ID, VITE_UMAMI_HOST } =
process.env;
const {
VITE_PORT,
BROWSER,
VITE_UMAMI_WEBSITE_ID,
VITE_UMAMI_HOST,
VITE_GRAASP_API_HOST,
} = process.env;
// compute the port to use
const PORT = parseInt(VITE_PORT || '3114', 10);
// compute whether we should open the browser
Expand All @@ -34,6 +39,17 @@ const config = ({ mode }: { mode: string }): UserConfigExport => {
watch: {
ignored: ['**/coverage/**', '**/cypress/downloads/**'],
},
proxy: {
// send requests made to `/api` to the backend running on a different port
// this allows to how have to specify a different host on the requests
// in production the load balancer will play this role.
'/api': {
target: VITE_GRAASP_API_HOST ?? 'http://localhost:3000',
changeOrigin: true,
// remove the "api" part
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
preview: {
port: PORT,
Expand Down

0 comments on commit f298e08

Please sign in to comment.