mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Partial migration to ASP.NET Core 1.0 RC2 (done the core packages, plus the ES2015/Webpack samples, and the Angular2Spa template). Only verified it builds/runs on .NET Core - not checked on net451.
This commit is contained in:
@@ -2,7 +2,7 @@ using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Microsoft.AspNet.AngularServices {
|
||||
var responseBody = await response.Content.ReadAsStringAsync();
|
||||
return new HtmlString(FormatAsScript(url, response.StatusCode, responseBody));
|
||||
} catch (Exception ex) {
|
||||
var logger = (ILogger)html.ViewContext.HttpContext.ApplicationServices.GetService(typeof (ILogger));
|
||||
var logger = (ILogger)html.ViewContext.HttpContext.RequestServices.GetService(typeof (ILogger));
|
||||
if (logger != null) {
|
||||
logger.LogWarning("Error priming cache for URL: " + url, ex);
|
||||
}
|
||||
|
||||
@@ -13,21 +13,19 @@
|
||||
"defaultNamespace": "Microsoft.AspNet.AngularServices"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": { },
|
||||
"dotnet5.4": {
|
||||
"dnx451": {},
|
||||
"netstandard1.5": {
|
||||
"imports": [
|
||||
"dotnet5.6",
|
||||
"portable-net451+win8"
|
||||
],
|
||||
"dependencies": {
|
||||
"Microsoft.CSharp": "4.0.1-beta-*",
|
||||
"System.Collections": "4.0.11-beta-*",
|
||||
"System.Linq": "4.0.1-beta-*",
|
||||
"System.Net.Http": "4.0.1-beta-*",
|
||||
"System.Runtime": "4.0.21-beta-*",
|
||||
"System.Threading": "4.0.11-beta-*"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
|
||||
"Microsoft.AspNet.NodeServices": "1.0.0-alpha7",
|
||||
"Microsoft.AspNet.SpaServices": "1.0.0-alpha7-1"
|
||||
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-*",
|
||||
"Microsoft.AspNet.NodeServices": "1.0.0-*",
|
||||
"Microsoft.AspNet.SpaServices": "1.0.0-*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
namespace Microsoft.AspNet.NodeServices {
|
||||
public static class Configuration {
|
||||
@@ -15,9 +16,9 @@ namespace Microsoft.AspNet.NodeServices {
|
||||
|
||||
public static void AddNodeServices(this IServiceCollection serviceCollection, NodeServicesOptions options) {
|
||||
serviceCollection.AddSingleton(typeof(INodeServices), (serviceProvider) => {
|
||||
var appEnv = serviceProvider.GetRequiredService<IApplicationEnvironment>();
|
||||
var hostEnv = serviceProvider.GetRequiredService<IHostingEnvironment>();
|
||||
if (string.IsNullOrEmpty(options.ProjectPath)) {
|
||||
options.ProjectPath = appEnv.ApplicationBasePath;
|
||||
options.ProjectPath = hostEnv.ContentRootPath;
|
||||
}
|
||||
return CreateNodeServices(options);
|
||||
});
|
||||
|
||||
@@ -10,23 +10,24 @@
|
||||
"url": "git://github.com/aspnet/nodeservices"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final",
|
||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final",
|
||||
"Newtonsoft.Json": "8.0.1-beta3",
|
||||
"Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-*",
|
||||
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0-*",
|
||||
"Newtonsoft.Json": "8.0.3",
|
||||
"System.Net.Http": "4.0.1-beta-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": { },
|
||||
"dotnet5.4": {
|
||||
"dnx451": {},
|
||||
"netstandard1.5": {
|
||||
"imports": [
|
||||
"dotnet5.6",
|
||||
"portable-net451+win8"
|
||||
],
|
||||
"dependencies": {
|
||||
"Microsoft.CSharp": "4.0.1-beta-*",
|
||||
"System.Collections": "4.0.11-beta-*",
|
||||
"System.Console": "4.0.0-beta-*",
|
||||
"System.Text.Encoding": "4.0.11-*",
|
||||
"System.Text.RegularExpressions": "4.0.10",
|
||||
"System.Diagnostics.Process": "4.1.0-beta-*",
|
||||
"System.IO.FileSystem": "4.0.1-beta-*",
|
||||
"System.Linq": "4.0.1-beta-*",
|
||||
"System.Text.RegularExpressions": "4.0.11-beta-*",
|
||||
"System.Threading": "4.0.11-beta-*"
|
||||
"System.Console": "4.0.0-beta-*"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -13,19 +13,18 @@
|
||||
"defaultNamespace": "Microsoft.AspNet.ReactServices"
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
|
||||
"Microsoft.AspNet.NodeServices": "1.0.0-alpha7",
|
||||
"Microsoft.AspNet.SpaServices": "1.0.0-alpha7-1"
|
||||
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-*",
|
||||
"Microsoft.AspNet.NodeServices": "1.0.0-*",
|
||||
"Microsoft.AspNet.SpaServices": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": { },
|
||||
"dotnet5.4": {
|
||||
"dnx451": {},
|
||||
"netstandard1.5": {
|
||||
"imports": [
|
||||
"dotnet5.6",
|
||||
"portable-net451+win8"
|
||||
],
|
||||
"dependencies": {
|
||||
"Microsoft.CSharp": "4.0.1-beta-*",
|
||||
"System.Collections": "4.0.11-beta-*",
|
||||
"System.Linq": "4.0.1-beta-*",
|
||||
"System.Runtime": "4.0.21-beta-*",
|
||||
"System.Threading": "4.0.11-beta-*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Extensions;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.AspNet.NodeServices;
|
||||
using Microsoft.AspNet.Razor.TagHelpers;
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -28,16 +31,18 @@ namespace Microsoft.AspNet.SpaServices.Prerendering
|
||||
[HtmlAttributeName(PrerenderWebpackConfigAttributeName)]
|
||||
public string WebpackConfigPath { get; set; }
|
||||
|
||||
[HtmlAttributeNotBound]
|
||||
[ViewContext]
|
||||
public ViewContext ViewContext { get; set; }
|
||||
|
||||
private string applicationBasePath;
|
||||
private IHttpContextAccessor contextAccessor;
|
||||
private INodeServices nodeServices;
|
||||
|
||||
public PrerenderTagHelper(IServiceProvider serviceProvider, IHttpContextAccessor contextAccessor)
|
||||
public PrerenderTagHelper(IServiceProvider serviceProvider)
|
||||
{
|
||||
var appEnv = (IApplicationEnvironment)serviceProvider.GetService(typeof(IApplicationEnvironment));
|
||||
this.contextAccessor = contextAccessor;
|
||||
var hostEnv = (IHostingEnvironment)serviceProvider.GetService(typeof (IHostingEnvironment));
|
||||
this.nodeServices = (INodeServices)serviceProvider.GetService(typeof (INodeServices)) ?? fallbackNodeServices;
|
||||
this.applicationBasePath = appEnv.ApplicationBasePath;
|
||||
this.applicationBasePath = hostEnv.ContentRootPath;
|
||||
|
||||
// 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.
|
||||
@@ -51,7 +56,7 @@ namespace Microsoft.AspNet.SpaServices.Prerendering
|
||||
|
||||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
|
||||
{
|
||||
var request = this.contextAccessor.HttpContext.Request;
|
||||
var request = this.ViewContext.HttpContext.Request;
|
||||
var result = await Prerenderer.RenderToString(
|
||||
applicationBasePath: this.applicationBasePath,
|
||||
nodeServices: this.nodeServices,
|
||||
@@ -59,7 +64,7 @@ namespace Microsoft.AspNet.SpaServices.Prerendering
|
||||
exportName = this.ExportName,
|
||||
webpackConfig = this.WebpackConfigPath
|
||||
},
|
||||
requestAbsoluteUrl: UriHelper.GetEncodedUrl(this.contextAccessor.HttpContext.Request),
|
||||
requestAbsoluteUrl: UriHelper.GetEncodedUrl(request),
|
||||
requestPathAndQuery: request.Path + request.QueryString.Value);
|
||||
output.Content.SetHtmlContent(result.Html);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Microsoft.AspNet.SpaServices
|
||||
{
|
||||
@@ -17,7 +17,7 @@ namespace Microsoft.AspNet.SpaServices
|
||||
this.clientRouteTokenName = clientRouteTokenName;
|
||||
}
|
||||
|
||||
public bool Match(HttpContext httpContext, IRouter route, string routeKey, IDictionary<string, object> values, RouteDirection routeDirection)
|
||||
public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
|
||||
{
|
||||
var clientRouteValue = (values[this.clientRouteTokenName] as string) ?? string.Empty;
|
||||
return !HasDotInLastSegment(clientRouteValue);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Routing;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNet.SpaServices;
|
||||
|
||||
// Putting in this namespace so it's always available whenever MapRoute is
|
||||
namespace Microsoft.AspNet.Builder
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
public static class SpaRouteExtensions
|
||||
{
|
||||
|
||||
@@ -3,8 +3,8 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace Microsoft.AspNet.SpaServices.Webpack
|
||||
{
|
||||
|
||||
@@ -3,11 +3,13 @@ using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.NodeServices;
|
||||
using Microsoft.AspNet.SpaServices.Webpack;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
// Putting in this namespace so it's always available whenever MapRoute is
|
||||
namespace Microsoft.AspNet.Builder
|
||||
namespace Microsoft.AspNetCore.Builder
|
||||
{
|
||||
public static class WebpackDevMiddleware
|
||||
{
|
||||
@@ -30,10 +32,10 @@ namespace Microsoft.AspNet.Builder
|
||||
// because it must *not* restart when files change (if it did, you'd lose all the benefits of Webpack
|
||||
// middleware). And since this is a dev-time-only feature, it doesn't matter if the default transport isn't
|
||||
// as fast as some theoretical future alternative.
|
||||
var appEnv = (IApplicationEnvironment)appBuilder.ApplicationServices.GetService(typeof(IApplicationEnvironment));
|
||||
var hostEnv = (IHostingEnvironment)appBuilder.ApplicationServices.GetService(typeof (IHostingEnvironment));
|
||||
var nodeServices = Configuration.CreateNodeServices(new NodeServicesOptions {
|
||||
HostingModel = NodeHostingModel.Http,
|
||||
ProjectPath = appEnv.ApplicationBasePath,
|
||||
ProjectPath = hostEnv.ContentRootPath,
|
||||
WatchFileExtensions = new string[] {} // Don't watch anything
|
||||
});
|
||||
|
||||
@@ -43,7 +45,7 @@ namespace Microsoft.AspNet.Builder
|
||||
|
||||
// Tell Node to start the server hosting webpack-dev-middleware
|
||||
var devServerOptions = new {
|
||||
webpackConfigPath = Path.Combine(appEnv.ApplicationBasePath, options.ConfigFile ?? DefaultConfigFile),
|
||||
webpackConfigPath = Path.Combine(hostEnv.ContentRootPath, options.ConfigFile ?? DefaultConfigFile),
|
||||
suppliedOptions = options
|
||||
};
|
||||
var devServerInfo = nodeServices.InvokeExport<WebpackDevServerInfo>(nodeScript.FileName, "createWebpackDevServer", JsonConvert.SerializeObject(devServerOptions)).Result;
|
||||
|
||||
@@ -13,13 +13,17 @@
|
||||
"projectUrl": "",
|
||||
"licenseUrl": "",
|
||||
"dependencies": {
|
||||
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
|
||||
"Microsoft.AspNet.Routing": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.NodeServices": "1.0.0-alpha7"
|
||||
"Microsoft.AspNetCore.Mvc": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.Routing": "1.0.0-*",
|
||||
"Microsoft.AspNet.NodeServices": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": { },
|
||||
"dotnet5.4": {
|
||||
"dnx451": {},
|
||||
"netstandard1.5": {
|
||||
"imports": [
|
||||
"dotnet5.6",
|
||||
"portable-net451+win8"
|
||||
],
|
||||
"dependencies": {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user