Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

Commit

Permalink
Default routing (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
mars authored Dec 23, 2018
1 parent f81fbdf commit ea2acbc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .buildpacks
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/mars/create-react-app-inner-buildpack.git#v7.0.0
https://github.com/mars/create-react-app-inner-buildpack.git#v8.0.0
https://github.com/heroku/heroku-buildpack-static.git
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Deploy React.js web apps generated with [create-react-app](https://github.com/fa
* 👓 [Customization](#user-content-customization)
* [Procfile](#user-content-procfile)
* [Web server](#user-content-web-server)
* [Routing clean URLs](#user-content-routing-clean-urls)
* [Routing](#user-content-routing)
* [HTTPS-only](#user-content-https-only)
* [Proxy](#user-content-proxy)
* [Environment variables](#user-content-environment-variables)
Expand Down Expand Up @@ -194,20 +194,6 @@ The config file `static.json` should be committed at the root of the repo. It wi

The default `static.json`, if it does not exist in the repo, is:

```json
{ "root": "build/" }
```

### Changing the root

If a different web server `"root"` is specified, such as with a highly customized, ejected create-react-app project, then the new bundle location may need to be [set to enable runtime environment variables](#user-content-custom-bundle-location).

### Routing clean URLs

[React Router](https://github.com/ReactTraining/react-router) (not included) may easily use hash-based URLs like `https://example.com/index.html#/users/me/edit`. This is nice & easy when getting started with local development, but for a public app you probably want real URLs like `https://example.com/users/me/edit`.

Create a `static.json` file at the root of the repo to configure the web server for clean [`browserHistory` with React Router v3](https://github.com/ReactTraining/react-router/blob/v3/docs/guides/Histories.md#browserhistory) & [`BrowserRouter` with v4](https://reacttraining.com/react-router/web/api/BrowserRouter):

```json
{
"root": "build/",
Expand All @@ -217,7 +203,15 @@ Create a `static.json` file at the root of the repo to configure the web server
}
```

👓 See [custom routing w/ the static buildpack](https://github.com/heroku/heroku-buildpack-static#custom-routes).
### Changing the root

If a different web server `"root"` is specified, such as with a highly customized, ejected create-react-app project, then the new bundle location may need to be [set to enable runtime environment variables](#user-content-custom-bundle-location).

### Routing

🚥 ***Client-side routing is supported by default.** Any server request that would result in 404 Not Found returns the React app.*

👓 See [custom routing w/ the static buildpack](https://github.com/heroku/heroku-buildpack-static/blob/master/README.md#user-content-custom-routes).

### HTTPS-only

Expand All @@ -226,6 +220,9 @@ Enforce secure connections by automatically redirecting insecure requests to **h
```json
{
"root": "build/",
"routes": {
"/**": "index.html"
},
"https_only": true
}
```
Expand All @@ -235,16 +232,19 @@ Prevent downgrade attacks with [HTTP strict transport security](https://develope
```json
{
"root": "build/",
"routes": {
"/**": "index.html"
},
"https_only": true,
"headers": {
"/**": {
"Strict-Transport-Security": "max-age=7776000"
"Strict-Transport-Security": "max-age=31557600"
}
}
}
```

* `max-age` is the number of seconds to enforce HTTPS since the last connection; the example is 90-days
* `max-age` is the number of seconds to enforce HTTPS since the last connection; the example is one-year

### Proxy

Expand Down Expand Up @@ -273,6 +273,9 @@ Add `"proxies"` to `static.json`:
```json
{
"root": "build/",
"routes": {
"/**": "index.html"
},
"proxies": {
"/api/": {
"origin": "${API_URL}"
Expand Down

0 comments on commit ea2acbc

Please sign in to comment.