Skip to content

Add possibility to force client-side inference of HMR endpoint #3620

Open
@TobbenTM

Description

@TobbenTM

What problem does this feature solve?

Currently it is not possible to run the vue-cli serve behind a SSL proxy, since the cli hardcodes the HMR endpoint:

const sockjsUrl = publicUrl
// explicitly configured via devServer.public
? `?${publicUrl}/sockjs-node`
: isInContainer
// can't infer public netowrk url if inside a container...
// use client-side inference (note this would break with non-root publicPath)
? ``
// otherwise infer the url
: `?` + url.format({
protocol,
port,
hostname: urls.lanUrlForConfig || 'localhost',
pathname: '/sockjs-node'
})

Ideally, the HMR requests would also be routed through the proxy, eliminating the need for any additional configuration of vue-cli (adding SSL certificates, etc).

As per the webpack documentation (https://webpack.js.org/configuration/dev-server/#devserverpublic), by default the client will guess the HMR endpoint based in window.location, which would solve this issue. However, there is no way to avoid the above mentioned hardcoding unless we're running the cli in a container, which is not really a solution.

A common use-case for this is how ASP.Net now does SPA integration; they proxy the SPA content to the actual framework dev servers (directly to create-react-app, etc). A Vue.js implementation of this has been made (https://github.com/EEParker/aspnetcore-vueclimiddleware), but it cannot alter the HMR endpoint without also modifying the dev server endpoint, which results in already occupied ports. The closest solution today is to edit the vue configuration to match each devs environment with something like:

module.exports = {
    devServer: {
        public: 'https://localhost:44393/'
    }
};

What does the proposed API look like?

Update vue.config.js with additional option:

module.exports = {
    devServer: {
        clientsidePublicInference: true
    }
}

Would be nice if a command line parameter would also be available, or environment variables, so tools like the above mentioned "aspnetcore-vueclimiddleware" can set this option without modifying configuration.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions