Skip to content

Commit

Permalink
#267 frontend: set correct hmr host depending on host environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolkenfarmer committed Jul 11, 2024
1 parent 7f52a08 commit f490250
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions frontend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ services:
- .env.${VITE_RUN_CONFIG}
ports:
- "5173:5173"
extra_hosts: # is used to ensure host.docker.internal resolves correctly on Linux systems
- "host.docker.internal:host-gateway"
14 changes: 8 additions & 6 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import {fileURLToPath, URL} from 'node:url'
import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'

function isNotDocker() {
const b = !process.env.IS_DOCKER
console.log('isDocker:', b)
return b
function getHmrHost() {
return process.env.IS_DOCKER ? 'host.docker.internal' : 'localhost'
}

// https://vitejs.dev/config/
Expand All @@ -25,7 +23,11 @@ export default defineConfig({
'process.env': process.env
},
server: {
// we do not need hmr in docker images + default address would not work (host: 'host.docker.internal' would be needed)
hmr: isNotDocker(),
// in order for hot module replacement to not throw an error inside the docker container
// (localhost would resolve to the container and not the host)
hmr: {
host: getHmrHost(),
port: 80
}
}
})

0 comments on commit f490250

Please sign in to comment.