mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2026-02-07 08:34:07 +00:00
Switch to using DI to acquire Node instances. Bump versions to alpha2.
This commit is contained in:
@@ -79,6 +79,9 @@ namespace MusicStore
|
||||
Mapper.CreateMap<ArtistResultDto, Artist>();
|
||||
Mapper.CreateMap<Genre, GenreResultDto>();
|
||||
Mapper.CreateMap<GenreResultDto, Genre>();
|
||||
|
||||
// Enable Node Services
|
||||
services.AddNodeServices();
|
||||
}
|
||||
|
||||
// Configure is called after ConfigureServices is called.
|
||||
@@ -108,17 +111,6 @@ namespace MusicStore
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
|
||||
var nodeInstance = new NodeInstance();
|
||||
app.Use(async (context, next) => {
|
||||
if (context.Request.Path.Value.EndsWith(".less")) {
|
||||
// Note: check for directory traversal
|
||||
var output = await nodeInstance.Invoke("lessCompiler.js", env.WebRootPath + context.Request.Path.Value);
|
||||
await context.Response.WriteAsync(output);
|
||||
} else {
|
||||
await next();
|
||||
}
|
||||
});
|
||||
|
||||
// Add static files to the request pipeline.
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
"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-alpha1"
|
||||
"Microsoft.AspNet.NodeServices.Angular": "1.0.0-alpha2"
|
||||
},
|
||||
"commands": {
|
||||
"web": "Microsoft.AspNet.Server.Kestrel"
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace ES2015Example.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public async Task<IActionResult> Index(int pageIndex)
|
||||
public IActionResult Index(int pageIndex)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
@@ -6,13 +6,17 @@ namespace ES2015Example.Controllers
|
||||
{
|
||||
public class ScriptController : Controller
|
||||
{
|
||||
private static NodeInstance nodeInstance = new NodeInstance();
|
||||
private INodeServices nodeServices;
|
||||
|
||||
public ScriptController(INodeServices nodeServices) {
|
||||
this.nodeServices = nodeServices;
|
||||
}
|
||||
|
||||
public async Task<ContentResult> Transpile(string filename)
|
||||
{
|
||||
// TODO: Don't hard-code wwwroot; use proper path conversions
|
||||
var fileContents = System.IO.File.ReadAllText("wwwroot/" + filename);
|
||||
var transpiledResult = await nodeInstance.Invoke("transpilation.js", fileContents, Request.Path.Value);
|
||||
var transpiledResult = await this.nodeServices.Invoke("transpilation.js", fileContents, Request.Path.Value);
|
||||
return Content(transpiledResult, "application/javascript");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Microsoft.Dnx.Runtime;
|
||||
using Microsoft.Framework.Configuration;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.Framework.Logging;
|
||||
using Microsoft.AspNet.NodeServices;
|
||||
|
||||
namespace ES2015Example
|
||||
{
|
||||
@@ -27,6 +28,9 @@ namespace ES2015Example
|
||||
{
|
||||
// Add MVC services to the services container.
|
||||
services.AddMvc();
|
||||
|
||||
// Enable Node Services
|
||||
services.AddNodeServices();
|
||||
}
|
||||
|
||||
// Configure is called after ConfigureServices is called.
|
||||
|
||||
@@ -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-alpha1"
|
||||
"Microsoft.AspNet.NodeServices": "1.0.0-alpha2"
|
||||
},
|
||||
"commands": {
|
||||
"web": "Microsoft.AspNet.Server.Kestrel"
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.AspNet.NodeServices;
|
||||
using Microsoft.AspNet.NodeServices.React;
|
||||
|
||||
namespace ReactExample.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private INodeServices nodeServices;
|
||||
|
||||
public HomeController(INodeServices nodeServices) {
|
||||
this.nodeServices = nodeServices;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Index(int pageIndex)
|
||||
{
|
||||
ViewData["ReactOutput"] = await ReactRenderer.RenderToString(
|
||||
ViewData["ReactOutput"] = await ReactRenderer.RenderToString(this.nodeServices,
|
||||
moduleName: "ReactApp/components/ReactApp.jsx",
|
||||
exportName: "ReactApp",
|
||||
baseUrl: Request.Path
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.NodeServices;
|
||||
using Microsoft.Dnx.Runtime;
|
||||
using Microsoft.Framework.Configuration;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
@@ -26,6 +27,9 @@ namespace ReactExample
|
||||
{
|
||||
// Add MVC services to the services container.
|
||||
services.AddMvc();
|
||||
|
||||
// Enable Node Services
|
||||
services.AddNodeServices();
|
||||
}
|
||||
|
||||
// Configure is called after ConfigureServices is called.
|
||||
|
||||
@@ -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-alpha1"
|
||||
"Microsoft.AspNet.NodeServices.React": "1.0.0-alpha2"
|
||||
},
|
||||
"commands": {
|
||||
"web": "Microsoft.AspNet.Server.Kestrel"
|
||||
|
||||
Reference in New Issue
Block a user