UNPKG

2.64 kBMarkdownView Raw
1![Module](https://img.shields.io/badge/%40platform-react.ssr-%23EA4E7E.svg)
2[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
3[![NPM](https://img.shields.io/npm/v/@platform/react.ssr.svg?colorB=blue&style=flat)](https://www.npmjs.com/package/@platform/react.ssr)
4![banner](https://user-images.githubusercontent.com/185555/63076436-66585300-bf89-11e9-8bca-0b80ae5313d0.png)
5
6A lightweight SSR (server-side-rendering) system for react apps bundled with ParcelJS and hosted on S3.
7
8<p>&nbsp;<p>
9
10#### Live Demo:
11https://ssr.platform.uiharness.com
12
13
14
15<p>&nbsp;<p>
16
17#### Highlights:
18
19- Store assets on [S3](https://aws.amazon.com/s3/) (or Digital Ocean [Spaces](https://www.digitalocean.com/products/spaces/)).
20- Serve entry HTML from server (immediate load from "server-side-render").
21- `307` redirect all other assets to S3/CDN (geo-edge cache).
22- Manage lifecycle with simple command-line tools:
23 - Bundle and push to S3 via command-line.
24 - Manage versioned releases (with simple roll-backs) across multiple sites/environments.
25 (eg. `dev`, `staging`, `prod`)
26
27<p>&nbsp;<p>
28
29
30
31![diagram](https://user-images.githubusercontent.com/185555/63561626-c6b14b00-c5ae-11e9-9102-796597f4e28c.png)
32
33
34## Setup
35
36 yarn add @platform/react.ssr
37
38
39<p>&nbsp;<p>
40
41
42## Workflow
43
44- Develop UI components on local dev-server within the [UIHarness](https://uiharness.com) or anything that can produce a javascript bundle (eg [ParcelJS](https://parceljs.org)):
45
46- Ensure the UI module has a `bundle` script within it's `package.json`.
47
48- Create an `ssr.yml` configuration file for the server.
49
50## Sample
51
52The `/sample/now` and `/sample/server` are expecting a `.env` file with your S3 account information:
53
54```
55#
56# Digital Ocean "SPACES" or AWS "S3" connection secrets.
57#
58SPACES_KEY="..."
59SPACES_SECRET="..."
60
61```
62
63These are referenced within the `ssr.yml` config file.
64
65
66#### Example sequence:
67
68```bash
69🌼
70cd sample/ui
71yarn start
72```
73
74
75Bundle a version and push it to S3:
76
77```bash
78🌳
79cd sample/server
80yarn ssr bundle
81```
82
83Release bundled version by updating manifest:
84
85```bash
86🌳
87cd sample/server
88yarn ssr release
89```
90
91Start local SSR server to test the bundle:
92
93```bash
94🌼
95cd sample/server
96yarn start
97```
98
99Open in `http://localhost` browser (address/port exposed in server startup log).
100
101
102<p>&nbsp;<p>
103
104## Routes
105The following system routes are exposed for examining meta-data about the current state and configuration of the server.
106
107```
108https://domain.com/.manifest
109https://domain.com/.manifest/summary
110https://domain.com/.manifest/summary/<site>
111```
112
113
114<p>&nbsp;<p>
115<p>&nbsp;<p>
116
117