mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Rename ES2015Transpilation sample to NodeServicesExamples (because will be adding some more examples here)
This commit is contained in:
2
samples/misc/NodeServicesExamples/.gitignore
vendored
Normal file
2
samples/misc/NodeServicesExamples/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/node_modules/
|
||||
/Properties/launchSettings.json
|
||||
18
samples/misc/NodeServicesExamples/Controllers/HomeController.cs
Executable file
18
samples/misc/NodeServicesExamples/Controllers/HomeController.cs
Executable file
@@ -0,0 +1,18 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace NodeServicesExamples.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public IActionResult Index(int pageIndex)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View("~/Views/Shared/Error.cshtml");
|
||||
}
|
||||
}
|
||||
}
|
||||
20
samples/misc/NodeServicesExamples/NodeServicesExamples.xproj
Normal file
20
samples/misc/NodeServicesExamples/NodeServicesExamples.xproj
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>6d4bcdd6-7951-449b-be55-cb7f014b7430</ProjectGuid>
|
||||
<RootNamespace>NodeServicesExamples</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\JavaScriptServices.sln\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<DevelopmentServerPort>2018</DevelopmentServerPort>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
65
samples/misc/NodeServicesExamples/Startup.cs
Executable file
65
samples/misc/NodeServicesExamples/Startup.cs
Executable file
@@ -0,0 +1,65 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.NodeServices;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.IO;
|
||||
|
||||
namespace NodeServicesExamples
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMvc();
|
||||
|
||||
// Enable Node Services
|
||||
services.AddNodeServices();
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory, IHostingEnvironment env, INodeServices nodeServices)
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
||||
// Dynamically transpile any .js files under the '/js/' directory
|
||||
app.Use(next => async context => {
|
||||
var requestPath = context.Request.Path.Value;
|
||||
if (requestPath.StartsWith("/js/") && requestPath.EndsWith(".js")) {
|
||||
var fileInfo = env.WebRootFileProvider.GetFileInfo(requestPath);
|
||||
if (fileInfo.Exists) {
|
||||
var transpiled = await nodeServices.Invoke<string>("transpilation.js", fileInfo.PhysicalPath, requestPath);
|
||||
await context.Response.WriteAsync(transpiled);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Not a JS file, or doesn't exist - let some other middleware handle it
|
||||
await next.Invoke(context);
|
||||
});
|
||||
|
||||
app.UseStaticFiles();
|
||||
loggerFactory.AddConsole();
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var host = new WebHostBuilder()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
.UseKestrel()
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
5
samples/misc/NodeServicesExamples/Views/Home/Index.cshtml
Executable file
5
samples/misc/NodeServicesExamples/Views/Home/Index.cshtml
Executable file
@@ -0,0 +1,5 @@
|
||||
Hello
|
||||
|
||||
@section scripts {
|
||||
<script src='js/main.js'></script>
|
||||
}
|
||||
6
samples/misc/NodeServicesExamples/Views/Shared/Error.cshtml
Executable file
6
samples/misc/NodeServicesExamples/Views/Shared/Error.cshtml
Executable file
@@ -0,0 +1,6 @@
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
11
samples/misc/NodeServicesExamples/Views/Shared/_Layout.cshtml
Executable file
11
samples/misc/NodeServicesExamples/Views/Shared/_Layout.cshtml
Executable file
@@ -0,0 +1,11 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>NodeServices Examples</title>
|
||||
</head>
|
||||
<body>
|
||||
@RenderBody()
|
||||
@RenderSection("scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
2
samples/misc/NodeServicesExamples/Views/_ViewImports.cshtml
Executable file
2
samples/misc/NodeServicesExamples/Views/_ViewImports.cshtml
Executable file
@@ -0,0 +1,2 @@
|
||||
@using NodeServicesExamples
|
||||
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers"
|
||||
3
samples/misc/NodeServicesExamples/Views/_ViewStart.cshtml
Executable file
3
samples/misc/NodeServicesExamples/Views/_ViewStart.cshtml
Executable file
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
1
samples/misc/NodeServicesExamples/appsettings.json
Executable file
1
samples/misc/NodeServicesExamples/appsettings.json
Executable file
@@ -0,0 +1 @@
|
||||
{}
|
||||
6
samples/misc/NodeServicesExamples/jsconfig.json
Normal file
6
samples/misc/NodeServicesExamples/jsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "commonjs"
|
||||
}
|
||||
}
|
||||
8
samples/misc/NodeServicesExamples/package.json
Normal file
8
samples/misc/NodeServicesExamples/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "nodeservicesexamples",
|
||||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"babel-core": "^6.7.4",
|
||||
"babel-preset-es2015": "^6.6.0"
|
||||
}
|
||||
}
|
||||
50
samples/misc/NodeServicesExamples/project.json
Executable file
50
samples/misc/NodeServicesExamples/project.json
Executable file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"tooling": {
|
||||
"defaultNamespace": "NodeServicesExamples"
|
||||
},
|
||||
"buildOptions": {
|
||||
"emitEntryPoint": true,
|
||||
"preserveCompilationContext": true
|
||||
},
|
||||
"runtimeOptions": {
|
||||
"gcServer": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"version": "1.0.0-rc2-*",
|
||||
"type": "platform"
|
||||
},
|
||||
"Microsoft.AspNetCore.Diagnostics": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.Mvc": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.StaticFiles": "1.0.0-*",
|
||||
"Microsoft.Extensions.Configuration.Json": "1.0.0-*",
|
||||
"Microsoft.Extensions.Logging.Console": "1.0.0-*",
|
||||
"Microsoft.NETCore.Platforms": "1.0.1-*",
|
||||
"Microsoft.Extensions.Logging.Debug": "1.0.0-*",
|
||||
"Microsoft.AspNetCore.NodeServices": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"imports": [
|
||||
"dotnet5.6",
|
||||
"dnxcore50",
|
||||
"portable-net45+win8"
|
||||
]
|
||||
}
|
||||
},
|
||||
"publishExclude": [
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"**.xproj",
|
||||
"**.user",
|
||||
"**.vspscc"
|
||||
],
|
||||
"scripts": {
|
||||
"prepublish": [ "npm install" ],
|
||||
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
|
||||
}
|
||||
}
|
||||
12
samples/misc/NodeServicesExamples/transpilation.js
Normal file
12
samples/misc/NodeServicesExamples/transpilation.js
Normal file
@@ -0,0 +1,12 @@
|
||||
var fs = require('fs');
|
||||
var babelCore = require('babel-core');
|
||||
|
||||
module.exports = function(cb, physicalPath, requestPath) {
|
||||
var originalContents = fs.readFileSync(physicalPath);
|
||||
var result = babelCore.transform(originalContents, {
|
||||
presets: ['es2015'],
|
||||
sourceMaps: 'inline',
|
||||
sourceFileName: '/sourcemapped' + requestPath
|
||||
});
|
||||
cb(null, result.code);
|
||||
}
|
||||
BIN
samples/misc/NodeServicesExamples/wwwroot/favicon.ico
Executable file
BIN
samples/misc/NodeServicesExamples/wwwroot/favicon.ico
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
7
samples/misc/NodeServicesExamples/wwwroot/js/main.js
Normal file
7
samples/misc/NodeServicesExamples/wwwroot/js/main.js
Normal file
@@ -0,0 +1,7 @@
|
||||
class Greeting {
|
||||
getMessage() {
|
||||
return 'Hello from the ES2015 class';
|
||||
}
|
||||
}
|
||||
|
||||
console.log(new Greeting().getMessage());
|
||||
9
samples/misc/NodeServicesExamples/wwwroot/web.config
Normal file
9
samples/misc/NodeServicesExamples/wwwroot/web.config
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
|
||||
</handlers>
|
||||
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" forwardWindowsAuthToken="false" startupTimeLimit="3600" />
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user