modern.js icon indicating copy to clipboard operation
modern.js copied to clipboard

[Bug]: Dev server behind proxy not working

Open march1993 opened this issue 3 years ago • 3 comments

Version

[email protected]
└── @modern-js/[email protected] -> ./node_modules/.pnpm/@[email protected][email protected]/node_modules/@modern-js/app-tools

Details

Standard webpack configuration not recognized. See https://webpack.js.org/configuration/dev-server/#websocketurl which says To get protocol/hostname/port from browser use webSocketURL: 'auto://0.0.0.0:0/ws'.

Reproduce link

about:blank

Reproduce Steps

put dev server behind any famous reverse proxy like nginx, caddy

march1993 avatar Sep 14 '22 09:09 march1993

websocketurl is a configuration of webpack-dev-server, which is not provided by webpack. Modern.js does not use webpack-dev-server as the dev server, so this configuration is not supported yet.

Currently modern.js dev server can be used with the proxy plugin, which is based on whistle.

Anyway, I think we will support websocketurl in the future.

chenjiahan avatar Sep 14 '22 14:09 chenjiahan

websocketurl is a configuration of webpack-dev-server, which is not provided by webpack. Modern.js does not use webpack-dev-server as the dev server, so this configuration is not supported yet.

Currently modern.js dev server can be used with the proxy plugin, which is based on whistle.

Anyway, I think we will support websocketurl in the future.

Is there any workaround right now? Missing auto-reloading is quite annoying. 😢

march1993 avatar Sep 22 '22 17:09 march1993

@march1993 Maybe you can try the proxy feature provided by modern.js, it should work well with dev server:

https://modernjs.dev/docs/apis/app/config/dev/proxy

chenjiahan avatar Sep 23 '22 01:09 chenjiahan

@chenjiahan With latest modernjs, the problem seems to be gone by setting host and path to empty as follows,

export default defineConfig({
  tools: {
    devServer: {
      client: {
        host: '',
        port: '',
      },
    },
  },
});

I don't know whether ws/wss is auto derived from the page location, but host and path are definitely working.

march1993 avatar Oct 25 '22 04:10 march1993

@chenjiahan With latest modernjs, the problem seems to be gone by setting host and path to empty as follows,

export default defineConfig({
  tools: {
    devServer: {
      client: {
        host: '',
        port: '',
      },
    },
  },
});

I don't know whether ws/wss is auto derived from the page location, but host and path are definitely working.

@march1993 yeah, the client.path/host configuration items in modern.js are related to webSocketURL. This is not clearly described in the documentation.

9aoy avatar Oct 25 '22 07:10 9aoy