Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
Actually works!!
  • Loading branch information
jods4 committed Mar 12, 2017
0 parents commit 4032533
Show file tree
Hide file tree
Showing 16 changed files with 24,976 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
obj
bin
.vscode
7 changes: 7 additions & 0 deletions App/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<h2>Server Clock</h2>
<div>
<button click.trigger="fetchTime()">Fetch time</button>
${time}
</div>
</template>
13 changes: 13 additions & 0 deletions App/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class AppViewModel {
time = "n/a";

activate() {
return this.fetchTime();
}

fetchTime() {
return fetch("/api/Time")
.then<any>(response => response.json())
.then(obj => this.time = obj.time);
}
}
8 changes: 8 additions & 0 deletions App/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {Aurelia, PLATFORM} from "aurelia-framework";

export function configure(aurelia: Aurelia) {
aurelia.use.standardConfiguration()
.developmentLogging();
aurelia.start()
.then(() => aurelia.setRoot(PLATFORM.moduleName("app")));
}
21 changes: 21 additions & 0 deletions AureliaDemo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="1.1.0" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0-msbuild3-final" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Microsoft.AspNetCore.Mvc;

namespace AureliaDemo.Controllers
{
public class HomeController : Controller
{
public IActionResult Index() => View();
}
}
12 changes: 12 additions & 0 deletions Controllers/TimeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace AureliaDemo.Controllers {
public class TimeController {
public object Index()
{
return new {
Time = DateTime.Now.ToString("T")
};
}
}
}
20 changes: 20 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.IO;
using Microsoft.AspNetCore.Hosting;

namespace AureliaDemo
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}
38 changes: 38 additions & 0 deletions Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.Webpack;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace AureliaDemo
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true
});
}

app.UseStaticFiles();

app.UseMvc(routes =>
{
routes.MapRoute("api", "api/{controller}/{action=Index}");
routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" });
});
}
}
}
11 changes: 11 additions & 0 deletions Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers"
@addTagHelper "*, Microsoft.AspNetCore.SpaServices"

<!doctype html>
<html>
<head>
<script defer src="/dist/app.js" asp-append-version="true"></script>
</head>
<body aurelia-app="main" asp-prerender-module="render" asp-prerender-timeout=2000>
</body>
</html>
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"license": "MIT",
"devDependencies": {
"aspnet-webpack": "^1.0.28",
"aurelia-webpack-plugin": "^2.0.0-rc.1",
"ts-loader": "^2.0.1",
"typescript": "^2.2.1",
"webpack": "^2.2.1",
"webpack-hot-middleware": "^2.17.1"
},
"dependencies": {
"aspnet-prerendering": "^2.0.3",
"aurelia-bootstrapper": "^2.1.1",
"jsdom": "^9.11.0",
"whatwg-fetch": "^2.0.3"
}
}
31 changes: 31 additions & 0 deletions render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const prerendering = require("aspnet-prerendering");
const jsdom = require("jsdom");

module.exports = prerendering.createServerRenderer(params =>
new Promise((resolve, reject) => {
jsdom.env({
html: "<html><body aurelia-app=main></body></html>",
scripts: ["/dist/app.js"],
url: "http://localhost:5000" + params.url,
features: {
FetchExternalResources: ["script"],
ProcessExternalResources: ["script"]
},
created: (err, window) => {
// HACK: "polyfill" missing stuff in JSDOM...
window.SVGElement = class SVGElement extends window.Element {};
window.requestAnimationFrame = f => window.setTimeout(f, 1000/60);

window.addEventListener("aurelia-composed", () => {
resolve({
html: window.document.body.innerHTML
});
window.close();
});
},
done: (err, window) => {
if (err) reject(err);
}
});
})
);
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es6",
"module": "es6",
"moduleResolution": "node",
"lib": [ "es6", "dom" ],
"importHelpers": true,

"experimentalDecorators": true
}
}
29 changes: 29 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const path = require("path");
const { AureliaPlugin } = require("aurelia-webpack-plugin");

module.exports = {
// The Fetch polyfill is required in JSDOM/NodeJS environment
entry: { main: ["whatwg-fetch", "aurelia-bootstrapper"] },

output: {
path: path.join(__dirname, "wwwroot", "dist"),
filename: "app.js",
publicPath: "/dist/",
},

resolve: {
extensions: [".ts", ".js"],
modules: ["App", "node_modules"],
},

module: {
rules: [
{ test: /\.html$/i, loaders: "html-loader" },
{ test: /\.ts$/i, loaders: "ts-loader" },
]
},

plugins: [
new AureliaPlugin(),
]
};
Loading

0 comments on commit 4032533

Please sign in to comment.