Giter Site home page Giter Site logo

rufer7 / aspnet-react-bff-proxy-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from isolutionsag/aspnet-react-bff-proxy-example

0.0 1.0 0.0 364 KB

ASP.NET Core / React Proxy BFF example

License: The Unlicense

JavaScript 3.87% C# 51.86% TypeScript 37.82% HTML 6.45%

aspnet-react-bff-proxy-example's Introduction

ASP.NET Core + React BFF Dev Proxy Sample app

This repo contains a sample app for hosting a React client from an ASP.NET Core WebAPI. During Development, requests for the client are forwarded to the vite development server, making the client application appear as if it was hosted through the server.

This enables the use of unified security headers in development and production, and allows us to use cookie authentication, as you'd use with a Razor/MVC or Blazor Server app.

Points of Interest:

  • AAD Config:
    • ServiceCollectionExtension.cs ~L43ff. Configures cookie auth
  • Dev Server Proxy:
    • Program.cs ~L106ff
    • _Host.cshtml
  • Security Headers + CSP with Nonce:
    • SecurityHeadersDefinitions.cs
  • Reading the Nonce in Client app:
    • main.tsx
  • CSP Workaround for Swagger:
    • SwaggerCspRelaxingHeaderService.cs
  • XSRF/CSRF Mitigation with Synchronizer Pattern:
    • _Host.cshtml - create tokens and pass then through cookies (one HTML-only, one not)
    • HttpClient.ts - read request token from non-HTML-only cookie, add to header
  • Swagger with CSRF:
    • ServiceCollectionExtension.cs ~L65ff
    • SwaggerHeaderFilter.cs - automatically add antiforgery request token (check swagger, it's shown as a form field)
  • PWA:
    • vite.config.ts - contains Vite-PWA config
    • service-worker.js - basic offline support

How to run

development mode

  1. Open the solution and launch the server app in Kestrel.
  2. Run the client app at /src/Client by running npm install then npm run dev
  3. Access the application at localhost:5001

production mode

  1. Build the client app at /src/Client by running npm install then npm build. The build output is placed in the server project's wwwroot folder
  2. Build the solution, making sure the wwwroot folder is included in the build
  3. Run the webAPI through Kestrel and access it via https

aspnet-react-bff-proxy-example's People

Contributors

gianlucamateo avatar rufer7 avatar

Watchers

 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.