mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Fix various path issues
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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/**/*"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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/**/*"
|
||||
|
||||
@@ -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<IApplicationEnvironment>();
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -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<bool> _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
|
||||
|
||||
@@ -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/**/*"
|
||||
]
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user