diff --git a/Microsoft.AspNet.NodeServices.Angular/AngularPrerenderTagHelper.cs b/Microsoft.AspNet.NodeServices.Angular/AngularPrerenderTagHelper.cs index 0de90ea..a5ffe68 100644 --- a/Microsoft.AspNet.NodeServices.Angular/AngularPrerenderTagHelper.cs +++ b/Microsoft.AspNet.NodeServices.Angular/AngularPrerenderTagHelper.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Extensions; +using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.NodeServices.Angular { @@ -23,15 +24,16 @@ namespace Microsoft.AspNet.NodeServices.Angular private IHttpContextAccessor contextAccessor; private INodeServices nodeServices; - public AngularPrerenderTagHelper(IServiceProvider nodeServices, IHttpContextAccessor contextAccessor) + public AngularPrerenderTagHelper(IServiceProvider serviceProvider, IHttpContextAccessor contextAccessor) { this.contextAccessor = contextAccessor; - this.nodeServices = (INodeServices)nodeServices.GetService(typeof (INodeServices)) ?? fallbackNodeServices; + this.nodeServices = (INodeServices)serviceProvider.GetService(typeof (INodeServices)) ?? fallbackNodeServices; // Consider removing the following. Having it means you can get away with not putting app.AddNodeServices() // in your startup file, but then again it might be confusing that you don't need to. if (this.nodeServices == null) { - this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http); + var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof (IApplicationEnvironment)); + this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, appEnv.ApplicationBasePath); } } diff --git a/Microsoft.AspNet.NodeServices.Angular/project.json b/Microsoft.AspNet.NodeServices.Angular/project.json index 18a0e91..df9e8f8 100644 --- a/Microsoft.AspNet.NodeServices.Angular/project.json +++ b/Microsoft.AspNet.NodeServices.Angular/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0-alpha4", + "version": "1.0.0-alpha5", "description": "Microsoft.AspNet.NodeServices.Angular Class Library", "authors": [ "Microsoft" @@ -25,8 +25,9 @@ } }, "dependencies": { - "Microsoft.AspNet.NodeServices": "1.0.0-alpha4", - "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8" + "Microsoft.AspNet.NodeServices": "1.0.0-alpha5", + "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8", + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8" }, "resource": [ "Content/**/*" diff --git a/Microsoft.AspNet.NodeServices.React/ReactPrerenderTagHelper.cs b/Microsoft.AspNet.NodeServices.React/ReactPrerenderTagHelper.cs index 7ca084a..b2df3b8 100644 --- a/Microsoft.AspNet.NodeServices.React/ReactPrerenderTagHelper.cs +++ b/Microsoft.AspNet.NodeServices.React/ReactPrerenderTagHelper.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Extensions; +using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.NodeServices.React { @@ -23,15 +24,16 @@ namespace Microsoft.AspNet.NodeServices.React private IHttpContextAccessor contextAccessor; private INodeServices nodeServices; - public ReactPrerenderTagHelper(IServiceProvider nodeServices, IHttpContextAccessor contextAccessor) + public ReactPrerenderTagHelper(IServiceProvider serviceProvider, IHttpContextAccessor contextAccessor) { this.contextAccessor = contextAccessor; - this.nodeServices = (INodeServices)nodeServices.GetService(typeof (INodeServices)) ?? fallbackNodeServices; + this.nodeServices = (INodeServices)serviceProvider.GetService(typeof (INodeServices)) ?? fallbackNodeServices; // Consider removing the following. Having it means you can get away with not putting app.AddNodeServices() // in your startup file, but then again it might be confusing that you don't need to. if (this.nodeServices == null) { - this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http); + var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment)); + this.nodeServices = fallbackNodeServices = Configuration.CreateNodeServices(NodeHostingModel.Http, appEnv.ApplicationBasePath); } } diff --git a/Microsoft.AspNet.NodeServices.React/project.json b/Microsoft.AspNet.NodeServices.React/project.json index c0c6b03..9b765c8 100644 --- a/Microsoft.AspNet.NodeServices.React/project.json +++ b/Microsoft.AspNet.NodeServices.React/project.json @@ -1,5 +1,5 @@ { - "version": "1.0.0-alpha4", + "version": "1.0.0-alpha5", "description": "Microsoft.AspNet.NodeServices.React Class Library", "authors": [ "Microsoft" @@ -25,8 +25,9 @@ } }, "dependencies": { - "Microsoft.AspNet.NodeServices": "1.0.0-alpha4", - "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8" + "Microsoft.AspNet.NodeServices": "1.0.0-alpha5", + "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8", + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8" }, "resource": [ "Content/**/*" diff --git a/Microsoft.AspNet.NodeServices/Configuration.cs b/Microsoft.AspNet.NodeServices/Configuration.cs index 2323812..7a21663 100644 --- a/Microsoft.AspNet.NodeServices/Configuration.cs +++ b/Microsoft.AspNet.NodeServices/Configuration.cs @@ -1,21 +1,23 @@ +using Microsoft.Dnx.Runtime; using Microsoft.Framework.DependencyInjection; namespace Microsoft.AspNet.NodeServices { public static class Configuration { public static void AddNodeServices(this IServiceCollection serviceCollection, NodeHostingModel hostingModel = NodeHostingModel.Http) { serviceCollection.AddSingleton(typeof(INodeServices), (serviceProvider) => { - return CreateNodeServices(hostingModel); + var appEnv = serviceProvider.GetRequiredService(); + return CreateNodeServices(hostingModel, appEnv.ApplicationBasePath); }); } - public static INodeServices CreateNodeServices(NodeHostingModel hostingModel) + public static INodeServices CreateNodeServices(NodeHostingModel hostingModel, string projectPath) { switch (hostingModel) { case NodeHostingModel.Http: - return new HttpNodeInstance(); + return new HttpNodeInstance(projectPath); case NodeHostingModel.InputOutputStream: - return new InputOutputStreamNodeInstance(); + return new InputOutputStreamNodeInstance(projectPath); default: throw new System.ArgumentException("Unknown hosting model: " + hostingModel.ToString()); } diff --git a/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs b/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs index 915f92a..6c94f2a 100644 --- a/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs +++ b/Microsoft.AspNet.NodeServices/HostingModels/HttpNodeInstance.cs @@ -15,8 +15,8 @@ namespace Microsoft.AspNet.NodeServices { private int _portNumber; - public HttpNodeInstance(int port = 0) - : base(EmbeddedResourceReader.Read(typeof(HttpNodeInstance), "/Content/Node/entrypoint-http.js"), port.ToString()) + public HttpNodeInstance(string projectPath, int port = 0) + : base(EmbeddedResourceReader.Read(typeof(HttpNodeInstance), "/Content/Node/entrypoint-http.js"), projectPath, port.ToString()) { } diff --git a/Microsoft.AspNet.NodeServices/HostingModels/InputOutputStreamNodeInstance.cs b/Microsoft.AspNet.NodeServices/HostingModels/InputOutputStreamNodeInstance.cs index 0f79935..e44d788 100644 --- a/Microsoft.AspNet.NodeServices/HostingModels/InputOutputStreamNodeInstance.cs +++ b/Microsoft.AspNet.NodeServices/HostingModels/InputOutputStreamNodeInstance.cs @@ -24,8 +24,8 @@ namespace Microsoft.AspNet.NodeServices { ContractResolver = new CamelCasePropertyNamesContractResolver() }; - public InputOutputStreamNodeInstance() - : base(EmbeddedResourceReader.Read(typeof(InputOutputStreamNodeInstance), "/Content/Node/entrypoint-stream.js")) + public InputOutputStreamNodeInstance(string projectPath) + : base(EmbeddedResourceReader.Read(typeof(InputOutputStreamNodeInstance), "/Content/Node/entrypoint-stream.js"), projectPath) { } diff --git a/Microsoft.AspNet.NodeServices/HostingModels/OutOfProcessNodeInstance.cs b/Microsoft.AspNet.NodeServices/HostingModels/OutOfProcessNodeInstance.cs index 5fa5e53..b2876a6 100644 --- a/Microsoft.AspNet.NodeServices/HostingModels/OutOfProcessNodeInstance.cs +++ b/Microsoft.AspNet.NodeServices/HostingModels/OutOfProcessNodeInstance.cs @@ -12,6 +12,7 @@ namespace Microsoft.AspNet.NodeServices { private object _childProcessLauncherLock; private bool disposed; private StringAsTempFile _entryPointScript; + private string _projectPath; private string _commandLineArguments; private Process _nodeProcess; private TaskCompletionSource _nodeProcessIsReadySource; @@ -24,10 +25,11 @@ namespace Microsoft.AspNet.NodeServices { } } - public OutOfProcessNodeInstance(string entryPointScript, string commandLineArguments = null) + public OutOfProcessNodeInstance(string entryPointScript, string projectPath, string commandLineArguments = null) { this._childProcessLauncherLock = new object(); this._entryPointScript = new StringAsTempFile(entryPointScript); + this._projectPath = projectPath; this._commandLineArguments = commandLineArguments ?? string.Empty; } @@ -49,20 +51,20 @@ namespace Microsoft.AspNet.NodeServices { lock (this._childProcessLauncherLock) { if (this._nodeProcess == null || this._nodeProcess.HasExited) { var startInfo = new ProcessStartInfo("node") { - Arguments = this._entryPointScript.FileName + " " + this._commandLineArguments, + Arguments = "\"" + this._entryPointScript.FileName + "\" " + this._commandLineArguments, UseShellExecute = false, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true }; - // Append current directory to NODE_PATH so it can locate node_modules + // Append projectPath to NODE_PATH so it can locate node_modules var existingNodePath = Environment.GetEnvironmentVariable("NODE_PATH") ?? string.Empty; if (existingNodePath != string.Empty) { existingNodePath += ":"; } - var nodePathValue = existingNodePath + Path.Combine(Directory.GetCurrentDirectory(), "node_modules"); + var nodePathValue = existingNodePath + Path.Combine(this._projectPath, "node_modules"); #if DNX451 startInfo.EnvironmentVariables.Add("NODE_PATH", nodePathValue); #else diff --git a/Microsoft.AspNet.NodeServices/project.json b/Microsoft.AspNet.NodeServices/project.json index 1c30add..1d42c81 100644 --- a/Microsoft.AspNet.NodeServices/project.json +++ b/Microsoft.AspNet.NodeServices/project.json @@ -1,19 +1,22 @@ { - "version": "1.0.0-alpha4", + "version": "1.0.0-alpha5", "description": "Microsoft.AspNet.NodeServices", - "authors": [ "Microsoft" ], - "tags": [""], + "authors": [ + "Microsoft" + ], + "tags": [ + "" + ], "projectUrl": "", "licenseUrl": "", - "dependencies": { - "System.Net.Http": "4.0.1-beta-23409", - "Newtonsoft.Json": "8.0.1-beta1", - "Microsoft.Framework.DependencyInjection": "1.0.0-beta8" + "System.Net.Http": "4.0.1-beta-23409", + "Newtonsoft.Json": "8.0.1-beta1", + "Microsoft.Framework.DependencyInjection": "1.0.0-beta8", + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-beta8" }, - "frameworks": { - "dnx451": { }, + "dnx451": {}, "dnxcore50": { "dependencies": { "Microsoft.CSharp": "4.0.1-beta-23217", @@ -28,8 +31,7 @@ } } }, - "resource": [ - "Content/**/*" + "Content/**/*" ] -} +} \ No newline at end of file diff --git a/samples/angular/MusicStore/project.json b/samples/angular/MusicStore/project.json index 94df1a6..07f8327 100755 --- a/samples/angular/MusicStore/project.json +++ b/samples/angular/MusicStore/project.json @@ -19,7 +19,8 @@ "EntityFramework.SQLite": "7.0.0-beta8", "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta8", "AutoMapper": "4.0.0-alpha1", - "Microsoft.AspNet.NodeServices.Angular": "1.0.0-alpha4" + "Microsoft.AspNet.NodeServices.Angular": "1.0.0-alpha5", + "Microsoft.AspNet.NodeServices": "1.0.0-alpha5" }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel" diff --git a/samples/misc/ES2015Transpilation/project.json b/samples/misc/ES2015Transpilation/project.json index d8be5db..b4b2604 100755 --- a/samples/misc/ES2015Transpilation/project.json +++ b/samples/misc/ES2015Transpilation/project.json @@ -16,7 +16,7 @@ "Microsoft.Framework.Logging": "1.0.0-beta8", "Microsoft.Framework.Logging.Console": "1.0.0-beta8", "Microsoft.Framework.Logging.Debug": "1.0.0-beta8", - "Microsoft.AspNet.NodeServices": "1.0.0-alpha3" + "Microsoft.AspNet.NodeServices": "1.0.0-alpha5" }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel" diff --git a/samples/react/ReactGrid/project.json b/samples/react/ReactGrid/project.json index ed9de5e..275ce96 100755 --- a/samples/react/ReactGrid/project.json +++ b/samples/react/ReactGrid/project.json @@ -16,7 +16,7 @@ "Microsoft.Framework.Logging": "1.0.0-beta8", "Microsoft.Framework.Logging.Console": "1.0.0-beta8", "Microsoft.Framework.Logging.Debug": "1.0.0-beta8", - "Microsoft.AspNet.NodeServices.React": "1.0.0-alpha4" + "Microsoft.AspNet.NodeServices.React": "1.0.0-alpha5" }, "commands": { "web": "Microsoft.AspNet.Server.Kestrel"