Files
JavaScriptServices/samples/misc/ES2015Transpilation/Controllers/ScriptController.cs
2015-11-02 11:15:34 -08:00

20 lines
688 B
C#

using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.NodeServices;
namespace ES2015Example.Controllers
{
public class ScriptController : Controller
{
private static NodeInstance nodeInstance = new NodeInstance();
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);
return Content(transpiledResult, "application/javascript");
}
}
}