package io.quarkus.vertx.http.runtime;

import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
import java.util.Set;

import org.eclipse.microprofile.config.spi.ConfigSource;

import io.quarkus.runtime.LaunchMode;

/**
 * Sets the default host config value, depending on the launch mode.
 * <p>
 * This can't be done with a normal default, is it changes based on the mode,
 * so instead it is provided as a low priority config source.
 */
public class HttpHostConfigSource implements ConfigSource, Serializable {

    public static final String QUARKUS_HTTP_HOST = "quarkus.http.host";
    private static final String ALL_INTERFACES = "0.0.0.0";

    private final int priority;

    public HttpHostConfigSource(int priority) {
        this.priority = priority;
    }

    @Override
    public Map<String, String> getProperties() {
        return Collections.singletonMap(QUARKUS_HTTP_HOST, getValue(QUARKUS_HTTP_HOST));
    }

    @Override
    public Set<String> getPropertyNames() {
        return Collections.singleton(QUARKUS_HTTP_HOST);
    }

    @Override
    public int getOrdinal() {
        return priority;
    }

    @Override
    public String getValue(String propertyName) {
        if (propertyName.equals(QUARKUS_HTTP_HOST)) {
            if (LaunchMode.isRemoteDev()) {
                // in remote-dev mode we need to listen on all interfaces
                return ALL_INTERFACES;
            }
            return LaunchMode.current().isDevOrTest() ? "localhost" : ALL_INTERFACES;
        }
        return null;
    }

    @Override
    public String getName() {
        return "Quarkus HTTP Host Default Value";
    }
}

@@ -1446,23 +1446,301 @@
         
-return 
+// In dev-mode we want to only listen on localhost so others on the network cannot connect to the application.%0A            // However, in WSL this would result in the application not being accessible,%0A            // so in that case, we launch it on all interfaces.%0A            return (
 LaunchMo
@@ -1765,16 +1765,29 @@
 OrTest()
+ && !isWSL())
  ? %22loca
@@ -1841,32 +1841,318 @@
 rn null;%0A    %7D%0A%0A
+    /**%0A     * @return %7B@code true%7D if the application is running in a WSL (Windows Subsystem for Linux) environment%0A     */%0A    private boolean isWSL() %7B%0A        var sysEnv = System.getenv();%0A        return sysEnv.containsKey(%22IS_WSL%22) %7C%7C sysEnv.containsKey(%22WSL_DISTRO_NAME%22);%0A    %7D%0A%0A
     @Override%0A  

Make Quarkus listen on all interfaces in WSL dev mode