Giter Club home page Giter Club logo

asp.net-core-react-and-ssr's Introduction

ASP.NET Core, React with SSR and Storybook · GitHub license PRs Welcome

Spin up your next project using this ASP.NET Core, React with Server-Side Rendering and Storybook boilerplate.

  • .NET Core 3.1.17: ASP.NET Core 3.1.17 to develop backend-code with C#
  • React 16.13.1 with Server-Side Rendering: to develop frontend-code with JavaScript. The boilerplate supports Server-Side Rendering
  • Storybook 5.3.17: to show clients prototypes of your pages quickly

Installation

Prerequisites

  • .NET Core 3.1.17: download and install the latest version
  • Node.js: download and install the latest LTS version
  • Docker: to run ASP.NET Core web app, Node for SSR and Storybook in containers. Download and install the latest version

Nice to have prerequisites

Quickstart

  1. Clone this repository

  2. Execute the following commands from the /fe folder to build fe:

    npm install

    npm run build-fe

  3. Open the project from the be folder in Visual Studio 2019, set the docker-compose project as the startup project and hit F5

The ASP.NET Core web application will be available at http://localhost:5000

The Storybook will be available at http://localhost:8091

How to develop new components and pages

To efficiently develop new components and pages, stop docker containers and start storybook and node server (for SSR) on your local machine. Remember to change SSR Node endpoint (ServerSideRenderingEndpoint) in appsettings.json and appsettings.Development.json under /be/src/Project/AspNetCore to http://localhost:3000

  1. Install npm packages from the /fe directory:

    npm install

  2. Start Storybook:

    npm run storybook

  3. Develop your React components and pages at /fe/src, reference them as shown in an example story at /fe/src/stories and preview your stories at http://localhost:9009

  4. Enable server-side rendering by adding your components and pages at /fe/server/middleware/renderer.js exactly as it has been done for HomePage and start the node server: from the /fe folder:

    node server/bootstrap.js

  5. You want to integrate your work into ASP.NET Core web application. To achieve this add your new page to /fe/webpack.config.js as shown in an example homepage component. To bundle, minify and copy the css and js assets to ASP.NET Core wwwroot execute:

    npm run build-fe

  6. Please reference the generated assets as shown in an example Index.cshtml at /be/src/Project/AspNetCore/Views

  7. Start Debugging (F5) or Start Without Debugging (Ctrl+F5) to see your pages live

Troubleshooting

  1. In case you experience a problem with webpack (especially on Windows), install it globally with the following command (yes, I know it's not recommended):

    npm install --global webpack

  2. In case you experience a problem with a missing NODE_ENV upon frontend build (yes, Windows) execute the command from the /fe folder:

    • Windows Command Prompt:

    SET NODE_ENV=production&&npm run build-fe

    • Windows Powershell:

    $env:NODE_ENV="production";npm run build-fe

  3. In case you experience a problem with a missing NODE_ENV upon node server run (for SSR) execute the command from the /fe folder:

    • Windows Command Prompt:

    SET NODE_ENV=production&&node server/bootstrap.js

    • Windows Powershell:

    $env:NODE_ENV="production";node server/bootstrap.js

  4. SocketException: No connection could be made because the target machine actively refused it:

Please make sure that your node server is up and running. Check if your ServerSideRenderingEndpoint in appsettings.json and appsettings.Development.json point to http://localhost:3000 (for local node server) or http://react-ssr-web:3000 (for Docker node server).

  1. window is not defined or global is not defined:

There is a good chance your window or global variables are undefined when doing SSR. Please have a look at Stack Overflow to find ways to fix your code.

Disclaimer

The boilerplate has been based on the CRA (Create React App), Create React App preset for Storybook and standard ASP.NET Core MVC template.

Documentation

You will learn more about this boilerplate on the website.

Contributing

Found a serious bug? Your pull request is very welcome :)

Support

To get support regarding ASP.NET Core, React and Server-Side Rendering, contact me directly.

License

This boilerplate is MIT licensed.

asp.net-core-react-and-ssr's People

Contributors

dawiddworak88 avatar

Watchers

 avatar  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.