Skip to content

Commit cd91862

Browse files
author
Ellis Kenyo
committed
Tidied up args
1 parent 6e30cb2 commit cd91862

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/Middleware/SpaServices.Extensions/src/DevelopmentServer/DevelopmentServerMiddleware.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static void Attach(
2525
ISpaBuilder spaBuilder,
2626
string npmScriptName,
2727
string waitText,
28+
Dictionary<string, string> extraArgs,
2829
string serverName = "App")
2930
{
3031
var sourcePath = spaBuilder.Options.SourcePath;
@@ -41,7 +42,7 @@ public static void Attach(
4142
// Start create-react-app and attach to middleware pipeline
4243
var appBuilder = spaBuilder.ApplicationBuilder;
4344
var logger = LoggerFinder.GetOrCreateLogger(appBuilder, LogCategoryName);
44-
var portTask = StartDevServerAsync(sourcePath, npmScriptName, waitText, serverName, logger);
45+
var portTask = StartDevServerAsync(sourcePath, npmScriptName, waitText, serverName, logger, extraArgs);
4546

4647
// Everything we proxy is hardcoded to target http://localhost because:
4748
// - the requests are always from the local machine (we're not accepting remote
@@ -73,17 +74,13 @@ private static async Task<int> StartDevServerAsync(
7374
{
7475
{ "PORT", portNumber.ToString() }
7576
};
76-
if (extraArgs == null)
77-
{
78-
extraArgs = new Dictionary<string, string>
79-
{
80-
{ "BROWSER", "None" }
81-
};
82-
}
83-
var extraKeys = new HashSet<string>(extraArgs.Keys);
84-
extraKeys.UnionWith(envVars.Keys);
77+
78+
waitText = waitText.Replace("$PORT", portNumber.ToString());
79+
80+
extraArgs = extraArgs.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Replace("$PORT", portNumber.ToString()));
81+
8582
var npmScriptRunner = new NpmScriptRunner(
86-
sourcePath, npmScriptName, null, envVars);
83+
sourcePath, npmScriptName, string.Join(" ", extraArgs.Select(x => x.Key + " " + x.Value).ToArray()), envVars);
8784
npmScriptRunner.AttachToLogger(logger);
8885

8986
using (var stdErrReader = new EventedStreamStringReader(npmScriptRunner.StdErr))

src/Middleware/SpaServices.Extensions/src/DevelopmentServer/DevelopmentServerMiddlewareExtensions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using Microsoft.AspNetCore.Builder;
55
using System;
6+
using System.Collections.Generic;
67

78
namespace Microsoft.AspNetCore.SpaServices.DevelopmentServer
89
{
@@ -27,7 +28,8 @@ public static void UseDevelopmentServer(
2728
this ISpaBuilder spaBuilder,
2829
string npmScript,
2930
string waitText,
30-
string serverName = "App")
31+
string serverName = "App",
32+
Dictionary<string, string> extraArgs = null)
3133
{
3234

3335
if (string.IsNullOrEmpty(waitText))
@@ -47,7 +49,7 @@ public static void UseDevelopmentServer(
4749
throw new InvalidOperationException($"To use {nameof(UseDevelopmentServer)}, you must supply a non-empty value for the {nameof(SpaOptions.SourcePath)} property of {nameof(SpaOptions)} when calling {nameof(SpaApplicationBuilderExtensions.UseSpa)}.");
4850
}
4951

50-
DevelopmentServerMiddleware.Attach(spaBuilder, npmScript, waitText, serverName);
52+
DevelopmentServerMiddleware.Attach(spaBuilder, npmScript, waitText, extraArgs, serverName);
5153
}
5254
}
5355
}

src/Middleware/SpaServices.Extensions/src/ReactDevelopmentServer/ReactDevelopmentServerMiddlewareExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static void UseReactDevelopmentServer(
2626
this ISpaBuilder spaBuilder,
2727
string npmScript)
2828
{
29-
DevelopmentServerMiddlewareExtensions.UseReactDevelopmentServer(spaBuilder, npmScript, "Starting the development server", "create-react-app");
29+
DevelopmentServerMiddlewareExtensions.UseDevelopmentServer(spaBuilder, npmScript, "Starting the development server", "create-react-app");
3030
}
3131
}
3232
}

0 commit comments

Comments
 (0)