From 3ee45ad9d3f5235623f4407eed4aaa5835499bfc Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Fri, 6 Apr 2018 01:37:14 -0500 Subject: [PATCH] React to feedback Add Dan --- docs/host-and-deploy/index.md | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/docs/host-and-deploy/index.md b/docs/host-and-deploy/index.md index 89f448d..8c1146b 100644 --- a/docs/host-and-deploy/index.md +++ b/docs/host-and-deploy/index.md @@ -13,19 +13,29 @@ uid: client-side/blazor/host-and-deploy/index --- # Host and deploy Blazor -By [Luke Latham](https://github.com/guardrex) and [Rainer Stropek](https://www.timecockpit.com) +By [Luke Latham](https://github.com/guardrex), [Rainer Stropek](https://www.timecockpit.com), and [Daniel Roth](https://github.com/danroth27) [!INCLUDE[](~/includes/blazor-preview-notice.md)] -## Reduction in payload size on build +## Publishing the app -As part of the build process, unused methods and assemblies are removed to reduce app download size and speed up load times. +Blazor apps are published for deployment in Release configuration with the [dotnet publish](https://docs.microsoft.com/dotnet/core/tools/dotnet-publish) command. An IDE may handle executing the `dotnet publish` command automatically using its built-in publishing features, so it might not be necessary to manually execute the command from a command prompt depending on the tooling used. + +```console +dotnet publish -c Release +``` + +`dotnet publish` triggers a [restore](https://docs.microsoft.com/dotnet/core/tools/dotnet-restore) of the project's dependencies and [builds](https://docs.microsoft.com/dotnet/core/tools/dotnet-build) the project before creating the assets for deployment. As part of the build process, unused methods and assemblies are removed to reduce app download size and speed up load times. The deployment is created in the */bin/Release/\/publish* folder. + +The assets in the *publish* folder are deployed to the web server. Deployment might be a manual or automated process depending on the tools being used. + +There are two deployment models for Blazor apps, [Hosted deployment with ASP.NET Core](#hosted-deployment-with-aspnet-core) and [Standalone deployment](#standalone-deployment). Hosted deployment uses an ASP.NET Core app on the server to host the Blazor app. Standalone deployment places the Blazor app on a static hosting web server or service, where .NET isn't used to serve the Blazor app. ## Hosted deployment with ASP.NET Core In a hosted deployment, an ASP.NET Core app handles single-page application routing and hosts the Blazor app's static files. The published app is deployed to the web server or hosting service. -In the ASP.NET Core app, each hosted Blazor app is configured with the `UseBlazor` extension method on [IApplicationBuilder](https://docs.microsoft.com/dotnet/api/microsoft.aspnetcore.builder.iapplicationbuilder) in `Startup.Configure`: +To host a Blazor app, the ASP.NET Core app references the Blazor app project. The ASP.NET Core app is then configured to host Blazor app with the `UseBlazor` extension method on [IApplicationBuilder](https://docs.microsoft.com/dotnet/api/microsoft.aspnetcore.builder.iapplicationbuilder) in `Startup.Configure`: ```csharp public void Configure(IApplicationBuilder app, IHostingEnvironment env) @@ -44,7 +54,7 @@ The `UseBlazor` extension method performs the following tasks: * Configures [Static File Middleware](https://docs.microsoft.com/aspnet/core/fundamentals/static-files) to serve Blazor's static assets from the *dist* folder. In the Development environment, the files in *wwwroot* are served. * Configure single-page application routing for files outside of the *_framework* folder, which serves the default page (*index.html*) for any request that hasn't been served by a prior Static File Middleware instance. -For information on ASP.NET Core app hosting and deployment, see [Host and deploy ASP.NET Core](https://docs.microsoft.com/aspnet/core/host-and-deploy). +When the ASP.NET Core app is published, the Blazor app is included in the published output so that the ASP.NET Core app and the Blazor app can be deployed together. For more information on ASP.NET Core app hosting and deployment, see [Host and deploy ASP.NET Core](https://docs.microsoft.com/aspnet/core/host-and-deploy). For information on deploying to Azure App Service, see the following topics: @@ -78,6 +88,12 @@ If a request is made using the browser's address bar for `www.contoso.com/About` Because browsers make requests to Internet-based hosts for client-side pages, web servers and services must rewrite all requests to the *index.html* page. When *index.html* is returned, the app's client-side router takes over and responds with the correct resource. +**App base path** + +The app base path is the virtual app root path on the server. For example, an app that resides on the Contoso server in a virtual folder at `/CoolBlazorApp` is reached at `https://www.contoso.com/CoolBlazorApp` and has a virtual base path of `/CoolBlazorApp`. By setting the app base path to `/CoolBlazorApp`, the app is made aware of where it virtually resides on the server. The app can use the app base path to construct URLs relative to the app root from a component that isn't in the root directory. This allows components that exist at different levels of a directory structure to correctly build links to other resources at locations throughout the app. + +In many hosting scenarios, the server's virtual path to the app is the root of the app. In these cases, the app base path is `/`, which is the default configuration for a Blazor app. In other hosting scenarios, such as GitHub Pages and IIS virtual directories, the app base path must be set to the server's virtual path to the app. To set the Blazor app's base path, update the base tag in *index.html* from `/` to `/`, where `` is the full virtual app root path on the server for the app. + ## Static hosting strategies for standalone apps When deploying a standalone Blazor app, any web server or hosting service that serves static files can host a Blazor app. @@ -147,6 +163,8 @@ For more information on production Nginx web server configuration, see [Creating ### Nginx in Docker +To host Blazor in Docker using Nginx, setup the Dockerfile to use the Alpine-based Nginx image. Update the Dockerfile to copy the *nginx.config* file into the container. + Add one line to the Dockerfile, as shown in the following example: ``` @@ -159,4 +177,4 @@ COPY nginx.conf /etc/nginx/nginx.conf To handle URL rewrites, add a *404.html* file with a script that handles redirecting the request to the *index.html* page. For an example implementation provided by the community, see [Single Page Apps for GitHub Pages](http://spa-github-pages.rafrex.com/) ([rafrex/spa-github-pages on GitHub](https://github.com/rafrex/spa-github-pages#readme)). An example using the community approach can be seen at [blazor-demo/blazor-demo.github.io on GitHub](https://github.com/blazor-demo/blazor-demo.github.io) ([live site](https://blazor-demo.github.io/)). -There's also a potential issue when using a project site instead of an organization site. Project sites have a path, so the base tag in *index.html* should be updated from `/` to `/`. +When using a project site instead of an organization site, update the base tag in *index.html* from `/` to `/`.