|
|
@@ -26,6 +26,7 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
|
|
|
{
|
|
|
var pkgManagerCommand = spaBuilder.Options.PackageManagerCommand;
|
|
|
var sourcePath = spaBuilder.Options.SourcePath;
|
|
|
+ var devServerPort = spaBuilder.Options.DevServerPort;
|
|
|
if (string.IsNullOrEmpty(sourcePath))
|
|
|
{
|
|
|
throw new ArgumentException("Cannot be null or empty", nameof(sourcePath));
|
|
|
@@ -39,7 +40,7 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
|
|
|
// Start create-react-app and attach to middleware pipeline
|
|
|
var appBuilder = spaBuilder.ApplicationBuilder;
|
|
|
var logger = LoggerFinder.GetOrCreateLogger(appBuilder, LogCategoryName);
|
|
|
- var portTask = StartCreateReactAppServerAsync(sourcePath, scriptName, pkgManagerCommand, logger);
|
|
|
+ var portTask = StartCreateReactAppServerAsync(sourcePath, scriptName, pkgManagerCommand, devServerPort, logger);
|
|
|
|
|
|
// Everything we proxy is hardcoded to target http://localhost because:
|
|
|
// - the requests are always from the local machine (we're not accepting remote
|
|
|
@@ -62,9 +63,12 @@ namespace Microsoft.AspNetCore.SpaServices.ReactDevelopmentServer
|
|
|
}
|
|
|
|
|
|
private static async Task<int> StartCreateReactAppServerAsync(
|
|
|
- string sourcePath, string scriptName, string pkgManagerCommand, ILogger logger)
|
|
|
+ string sourcePath, string scriptName, string pkgManagerCommand, int portNumber, ILogger logger)
|
|
|
{
|
|
|
- var portNumber = TcpPortFinder.FindAvailablePort();
|
|
|
+ if (portNumber == default(int))
|
|
|
+ {
|
|
|
+ portNumber = TcpPortFinder.FindAvailablePort();
|
|
|
+ }
|
|
|
logger.LogInformation($"Starting create-react-app server on port {portNumber}...");
|
|
|
|
|
|
var envVars = new Dictionary<string, string>
|