Giter Site home page Giter Site logo

cherscarlett / another-ssr-boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gtg092x/another-ssr-boilerplate

0.0 1.0 0.0 114 KB

A barebones SSR boilerplate used for some awesome Riot Games web products

Home Page: https://riot.com/2X2gNER

License: MIT License

JavaScript 100.00%

another-ssr-boilerplate's Introduction

Another SSR Boilerplate

From the Riot Tech blog article "Better Apps with React Server-Side Rendering".

Setup

# installs dependencies and sets up a local .env file
yarn

Development

yarn dev

Build

yarn build

App Architecture

This boilerplate contains some server code that can serve a React Application and an API that provides data for it.

The general rule of thumb is that anything inside src/app is client and server code while all code outside of src/app but inside of src is node server code.

src

Code for the entire application. It's bundled into lib when app is built.

src/api

A koa-router powered middleware that is our app's json api.

src/assets

Middleware that serves either static assets or proxies webpack-dev-server depending on the environment variable WEBPACK_PORT.

src/render

The React server renderer middleware. This takes the App from src/app and renders it on the server for us.

src/render/Html

Our broader layout file. This content is the "container" for the app. If you want to manage metadata, take a look at the NYT fork of React Helmet.

src/render/index

The actual middleware. This does three things:

  • Asynchronously Loads Redux Data
  • Synchronously Renders the App
  • Synchronously Renders an HTML Layout file that includes page title, etc.

This is analogous to the file src/app/main.js. This only runs on the server.

src/app

The React app. Most of the code in this folder will end up in a web browser, so don't do something crazy like import postgres.

src/app/services

Here we define all of our standalone services that get injected into the app. This includes our redux store and our axios client.

These services should not rely on React components at all. They will be referenced before our server-side render when we asynchronously load our state.

src/app/main

The browser entry point. This is the one place you can stuff all the webpack magic in the world, the server won't see this file.

This is analogous to the file src/render/index.js. This only runs in the browser.

src/app/App

The main App, here we set global contexts and treat the main Router as our only child.

src/app/Routes

A react router Switch that contains references to all of our scenes.

Because we want to define all of our routes in one place, Our data loading is done here as well.

src/app/Scenes

Our different React views as pages. These are your app!

If they need remote data, you'll want to load that in our Routes file before you use a redux selector to access that data here.

Thanks

You! You're giving React SSR a shot, that makes you awesome.

License

MIT

another-ssr-boilerplate's People

Contributors

dependabot[bot] avatar gtg092x 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.