Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update doc server example to work from any directory #1988

Merged
merged 2 commits into from
Apr 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/react-scripts/template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1242,10 +1242,10 @@ const express = require('express');
const path = require('path');
const app = express();

app.use(express.static('./build'));
app.use(express.static(path.join(__dirname, 'build')));

app.get('/', function (req, res) {
res.sendFile(path.join(__dirname, './build', 'index.html'));
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});

app.listen(9000);
Expand All @@ -1264,11 +1264,11 @@ If you use routers that use the HTML5 [`pushState` history API](https://develope
This is because when there is a fresh page load for a `/todos/42`, the server looks for the file `build/todos/42` and does not find it. The server needs to be configured to respond to a request to `/todos/42` by serving `index.html`. For example, we can amend our Express example above to serve `index.html` for any unknown paths:

```diff
app.use(express.static('./build'));
app.use(express.static(path.join(__dirname, 'build')));

-app.get('/', function (req, res) {
+app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, './build', 'index.html'));
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
```

Expand Down