mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Added OnBeforeStartExternalProcess callback which to NodeServicesOptions (and OutOfProcessNodeInstance, SocketNodeInstance and HttpNodeInstance) to configure environment of the node.exe process to be started, and the path to the node executable itself. Fixes #20
This commit is contained in:
committed by
SteveSandersonMS
parent
057efb43c8
commit
7119815d04
@@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.NodeServices
|
||||
HostingModel = DefaultNodeHostingModel;
|
||||
WatchFileExtensions = (string[])DefaultWatchFileExtensions.Clone();
|
||||
}
|
||||
|
||||
public Action<System.Diagnostics.ProcessStartInfo> OnBeforeStartExternalProcess { get; set; }
|
||||
public NodeHostingModel HostingModel { get; set; }
|
||||
public Func<INodeInstance> NodeInstanceFactory { get; set; }
|
||||
public string ProjectPath { get; set; }
|
||||
|
||||
@@ -32,14 +32,15 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
private bool _disposed;
|
||||
private int _portNumber;
|
||||
|
||||
public HttpNodeInstance(string projectPath, string[] watchFileExtensions, int port = 0)
|
||||
public HttpNodeInstance(string projectPath, string[] watchFileExtensions, int port = 0, Action<System.Diagnostics.ProcessStartInfo> onBeforeStartExternalProcess = null)
|
||||
: base(
|
||||
EmbeddedResourceReader.Read(
|
||||
typeof(HttpNodeInstance),
|
||||
"/Content/Node/entrypoint-http.js"),
|
||||
projectPath,
|
||||
watchFileExtensions,
|
||||
MakeCommandLineOptions(port))
|
||||
MakeCommandLineOptions(port),
|
||||
onBeforeStartExternalProcess)
|
||||
{
|
||||
_client = new HttpClient();
|
||||
}
|
||||
@@ -112,7 +113,8 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing) {
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (!_disposed)
|
||||
|
||||
@@ -31,10 +31,11 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
string entryPointScript,
|
||||
string projectPath,
|
||||
string[] watchFileExtensions,
|
||||
string commandLineArguments)
|
||||
string commandLineArguments,
|
||||
Action<System.Diagnostics.ProcessStartInfo> onBeforeStartExternalProcess = null)
|
||||
{
|
||||
_entryPointScript = new StringAsTempFile(entryPointScript);
|
||||
_nodeProcess = LaunchNodeProcess(_entryPointScript.FileName, projectPath, commandLineArguments);
|
||||
_nodeProcess = LaunchNodeProcess(_entryPointScript.FileName, projectPath, commandLineArguments, onBeforeStartExternalProcess);
|
||||
_watchFileExtensions = watchFileExtensions;
|
||||
_fileSystemWatcher = BeginFileWatcher(projectPath);
|
||||
ConnectToInputOutputStreams();
|
||||
@@ -111,7 +112,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
}
|
||||
}
|
||||
|
||||
private static Process LaunchNodeProcess(string entryPointFilename, string projectPath, string commandLineArguments)
|
||||
private static Process LaunchNodeProcess(string entryPointFilename, string projectPath, string commandLineArguments, Action<System.Diagnostics.ProcessStartInfo> onBeforeStartExternalProcess)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo("node")
|
||||
{
|
||||
@@ -136,6 +137,10 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
#else
|
||||
startInfo.Environment["NODE_PATH"] = nodePathValue;
|
||||
#endif
|
||||
if (onBeforeStartExternalProcess != null)
|
||||
{
|
||||
onBeforeStartExternalProcess(startInfo);
|
||||
}
|
||||
|
||||
var process = Process.Start(startInfo);
|
||||
|
||||
|
||||
@@ -36,13 +36,14 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
||||
private string _socketAddress;
|
||||
private VirtualConnectionClient _virtualConnectionClient;
|
||||
|
||||
public SocketNodeInstance(string projectPath, string[] watchFileExtensions, string socketAddress): base(
|
||||
public SocketNodeInstance(string projectPath, string[] watchFileExtensions, string socketAddress, Action<System.Diagnostics.ProcessStartInfo> onBeforeStartExternalProcess = null) : base(
|
||||
EmbeddedResourceReader.Read(
|
||||
typeof(SocketNodeInstance),
|
||||
"/Content/Node/entrypoint-socket.js"),
|
||||
projectPath,
|
||||
watchFileExtensions,
|
||||
MakeNewCommandLineOptions(socketAddress))
|
||||
MakeNewCommandLineOptions(socketAddress),
|
||||
onBeforeStartExternalProcess)
|
||||
{
|
||||
_socketAddress = socketAddress;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user