Git Product home page Git Product logo

aspnetcore-angular-ssr's Introduction

aspnetcore-angular-ssr

A simple ASP.NET Core Web API and Angular Client with server-side rendering.

  • The default Angular route displays the WeatherForecastListComponent.
  • This route gets its data via the WeatherForecastResolver.
  • The resolver uses the WeatherForecastService which makes the HTTP request to the Web API

Angular Client

Install Angular CLI and Angular-ESLint schematics globally

npm i -g @angular/cli @angular-devkit/core @angular-devkit/schematics @angular-eslint/schematics

Initialize an Angular app:

ng new ng-client --directory=ng-client --routing --skip-git --strict --style=scss --package-manager=npm --collection=@angular-eslint/schematics

Follow the instructions described in the official Angular Universal docs: https://angular.io/guide/universal

ng add @nguniversal/express-engine

Follow these instructions:

Update server.ts for Production (instructions taken from https://bossprogrammer.medium.com/how-to-deploy-an-angular-10-universal-app-with-server-side-rendering-to-azure-a2b90df9ca64 )

Replace this line in server.ts:

const distFolder = join(process.cwd(), 'dist/YOUR_APP_NAME/browser');

With:

let distFolder = join(process.cwd(), 'browser');
if (!existsSync(distFolder)) {
  distFolder = join(process.cwd(), 'dist/YOUR_APP_NAME/browser');
}

ASP.NET Core Web API

dotnet new webapi -n WebAPI -o WebAPI -f net5.0

The Web API runs on IIS Express when started in Visual Studio 2019: (as stated in launchSettings.json)

The Angular app uses the value from environment.ts as the base URL for HTTP requests.

HTTPS redirection is disabled in ASP.NET Core, otherwise HTTP requests in SSR development mode will fail.

Azure

Create an Azure App Service (Web App) with Stack ".NET 5"

Go To TLS/SSL Settings and enable "HTTPS Only"

Go to Configuration and add this application setting:

  • Key: WEBSITE_NODE_DEFAULT_VERSION
  • Value: ~12

Add/Edit Path Mappings:

Virtual Path Physical Path Type
/ site\wwwroot\ng-client Application
/webapi site\wwwroot\webapi Application

aspnetcore-angular-ssr's People

Contributors

mopinsk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.