Skip to content

Commit 67adcc5

Browse files
committed
Change to check for port with angular
1 parent b41fb0b commit 67adcc5

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

MyApp.Client/angular.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@
6565
"buildTarget": "MyApp.Client:build:development"
6666
}
6767
},
68-
"defaultConfiguration": "development",
69-
"options": {
70-
"proxyConfig": "src/proxy.conf.js"
71-
}
68+
"defaultConfiguration": "development"
7269
},
7370
"extract-i18n": {
7471
"builder": "@angular-devkit/build-angular:extract-i18n"

MyApp.Client/src/proxy.conf.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

MyApp/Program.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
services.AddServiceStack(typeof(MyServices).Assembly);
3939

4040
var app = builder.Build();
41-
var nodeProxy = new NodeProxy("http://127.0.0.1:4200") {
41+
var nodeProxy = new NodeProxy("http://localhost:4200") {
4242
Log = app.Logger
4343
};
4444

@@ -72,11 +72,20 @@
7272
// Proxy development HMR WebSocket and fallback routes to the Next server
7373
if (app.Environment.IsDevelopment())
7474
{
75-
// Start the Next.js dev server if the Next.js lockfile does not exist
76-
app.RunNodeProcess(nodeProxy,
77-
lockFile: "../MyApp.Client/dist/lock",
78-
workingDirectory: "../MyApp.Client");
79-
75+
// Start the Angular dev server if it's not running
76+
var portAvailable = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties()
77+
.GetActiveTcpListeners().All(x => x.Port != 4200);
78+
if (portAvailable && nodeProxy.TryStartNode("../MyApp.Client", out var process))
79+
{
80+
app.Lifetime.ApplicationStopping.Register(() => {
81+
if (!process.HasExited)
82+
{
83+
nodeProxy.Log.LogDebug("Terminating process: " + process.Id);
84+
process.Kill(entireProcessTree: true);
85+
}
86+
});
87+
}
88+
8089
app.UseWebSockets();
8190
app.MapViteHmr(nodeProxy);
8291
app.MapFallbackToNode(nodeProxy);

0 commit comments

Comments
 (0)