Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Hardcoded binding to 127.0.0.1 causing problems with some IP 6 operating systems #182

Open
gohf opened this issue Jan 6, 2023 · 1 comment

Comments

@gohf
Copy link

gohf commented Jan 6, 2023

Because this library has a hardcoded host binding of 127.0.0.1 it does not work with some operating systems.

In VueDevelopmentServerMiddleware.cs:

var targetUriTask = portTask.ContinueWith(
                task => new UriBuilder(https ? "https" : "http", "127.0.0.1", task.Result).Uri);

Testing on Fedora 37 produces an exception that effetivaley and accurately says the connection to the SPA host was refused. This is because the SPA is binding to localhost which is resolved to ::1 whereas this library is attempting to connect to 127.0.0.1.

Would it be possible to make the host binding configurable?

[18:18:12 ERR] An unhandled exception has occurred while executing the request.
System.Net.Http.HttpRequestException: Failed to proxy the request to http://127.0.0.1:8081/_loading/sse, because the request to the proxy target failed. Check that the proxy target server is running and accepting requests to http://127.0.0.1:8081/.

The underlying exception message was 'Connection refused (127.0.0.1:8081)'.Check the InnerException for more details.
 ---> System.Net.Http.HttpRequestException: Connection refused (127.0.0.1:8081)
 ---> System.Net.Sockets.SocketException (111): Connection refused
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
   at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.PerformProxyRequest(HttpContext context, HttpClient httpClient, Task`1 baseUriTask, CancellationToken applicationStoppingToken, Boolean proxy404s)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.SpaServices.Extensions.Proxy.SpaProxy.PerformProxyRequest(HttpContext context, HttpClient httpClient, Task`1 baseUriTask, CancellationToken applicationStoppingToken, Boolean proxy404s)
   at Microsoft.AspNetCore.Builder.SpaProxyingExtensions.<>c__DisplayClass2_0.<<UseProxyToSpaDevelopmentServer>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at MMRG.Thecosystems.Public.WebApp.Middleware.ReverseProxyMiddleware.Invoke(HttpContext context) in /home/hastiel/Documents/GitHub/mmrg-thecosystems/src/WebApps/Thecosystems.Public.WebApp/Middleware/ReverseProxy.cs:line 48
   at MMRG.Thecosystems.Public.WebApp.Middleware.AuthMiddleware.InvokeAsync(HttpContext context) in /home/hastiel/Documents/GitHub/mmrg-thecosystems/src/WebApps/Thecosystems.Public.WebApp/Middleware/AuthMiddleware.cs:line 58
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

@Diponchik
Copy link

Diponchik commented Jun 6, 2023

I have encountered the same issue. There are a few solutions to solve it:

  • Use another version of node.js which has a default host is 127.0.0.1
  • In package.json add ''--host 127.0.0.1' to script command.

They are not perfect solutions, so it would be nice to have an extra parameter to configure it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants