From e2a7d4fa40207a7f9d0dde00b5b8fb0ef043d32f Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Wed, 6 Dec 2017 23:35:16 +0000 Subject: [PATCH] Serve blazor.js in standalone site --- samples/BlazorStandalone/wwwroot/index.html | 3 ++- .../BlazorBrowserFileProvider.cs | 25 +++++++++++++++++++ .../Microsoft.Blazor.Browser.csproj | 6 ++++- src/Microsoft.Blazor.Browser/src/Boot.ts | 3 +-- .../BlazorAppBuilderExtensions.cs | 6 ++++- .../Microsoft.Blazor.Server.csproj | 2 ++ 6 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/Microsoft.Blazor.Browser/BlazorBrowserFileProvider.cs diff --git a/samples/BlazorStandalone/wwwroot/index.html b/samples/BlazorStandalone/wwwroot/index.html index 100e47440b..c3d471ecdc 100644 --- a/samples/BlazorStandalone/wwwroot/index.html +++ b/samples/BlazorStandalone/wwwroot/index.html @@ -6,5 +6,6 @@

Hello

+ - \ No newline at end of file + diff --git a/src/Microsoft.Blazor.Browser/BlazorBrowserFileProvider.cs b/src/Microsoft.Blazor.Browser/BlazorBrowserFileProvider.cs new file mode 100644 index 0000000000..e83c802ebc --- /dev/null +++ b/src/Microsoft.Blazor.Browser/BlazorBrowserFileProvider.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.Extensions.FileProviders; +using Microsoft.Extensions.Primitives; +using System; + +namespace Microsoft.Blazor.Browser +{ + public class BlazorBrowserFileProvider : IFileProvider + { + private EmbeddedFileProvider _embeddedFiles = new EmbeddedFileProvider( + typeof(BlazorBrowserFileProvider).Assembly, + "blazor"); + + public IFileInfo GetFileInfo(string subpath) + =>_embeddedFiles.GetFileInfo(subpath.Replace('/', '$')); + + public IDirectoryContents GetDirectoryContents(string subpath) + => throw new NotImplementedException(); // Don't need to support this + + public IChangeToken Watch(string filter) + => throw new NotImplementedException(); // Don't need to support this + } +} diff --git a/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj b/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj index 21b750d3d3..d7e17c08e1 100644 --- a/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj +++ b/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj @@ -7,11 +7,15 @@ ${DefaultItemExcludes};node_modules\** + + + + - + diff --git a/src/Microsoft.Blazor.Browser/src/Boot.ts b/src/Microsoft.Blazor.Browser/src/Boot.ts index 4e2801461b..0331260eb4 100644 --- a/src/Microsoft.Blazor.Browser/src/Boot.ts +++ b/src/Microsoft.Blazor.Browser/src/Boot.ts @@ -1,2 +1 @@ -const abc: string = "Hello"; -alert(abc); +console.log('Blazor is loading'); diff --git a/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs b/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs index 2dff0e53df..68932c449a 100644 --- a/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs +++ b/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs @@ -2,7 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.StaticFiles; +using Microsoft.Blazor.Browser; using Microsoft.Blazor.Mono; +using Microsoft.Extensions.FileProviders; using System.Collections.Generic; using System.Net.Mime; @@ -15,7 +17,9 @@ namespace Microsoft.AspNetCore.Builder applicationBuilder.UseStaticFiles(new StaticFileOptions { RequestPath = "/_framework", - FileProvider = new MonoStaticFileProvider(), + FileProvider = new CompositeFileProvider( + new MonoStaticFileProvider(), + new BlazorBrowserFileProvider()), ContentTypeProvider = CreateContentTypeProvider(), }); } diff --git a/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj b/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj index f749977536..b451283f02 100644 --- a/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj +++ b/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj @@ -6,9 +6,11 @@ + +