Solid start hmr with docker

Docker
Logo

Özgür Sargut

Published Jul 13, 24

·

Last Updated Jul 13, 24

Normally hmr works through web sockets but the problem is the web socket get its port randomly assigned at runtime. And we cant expose a random port.

How can we fix the port so its the same every time

Solid start uses vite so we can just configure the app.config.ts file to have:

import { defineConfig } from "@solidjs/start/config";

export default defineConfig({
  vite: {
    server: {
      hmr: {
        port: 5142,
      },
    },
  },
});

The hmr server is using the port 5142.

But now we have 2 errors WebSocket server error: Port is already in use problem is that we have 3 different environments and when we set the hmr port its uses the same port for all 3 environments(client, server, server-function). Which only allows one of the environments web socket to be able to start.

How do we make sure all the environments get unique ports so they can start

We just need different ports for all the environments.

import { defineConfig } from '@solidjs/start/config'

const wsPorts = {
  client: 5142,
  server: 5143,
  'server-function': 5144,
}

export default defineConfig({
  vite({ router }) {
    return {
      server: {
        hmr: {
          port: wsPorts[router],
        },
      },
    }
  },
});

Thanks for reading.