Skip to content

Commit febca13

Browse files
committed
also handle history fallback
1 parent 7a82c03 commit febca13

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ You will likely need to do some tuning to suit your own needs:
5252

5353
- Working with an existing backend server:
5454

55-
- The dev server is simply an [Express](http://expressjs.com/) server with [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) and [webpack-hot-middleware](https://github.com/glenjamin/webpack-hot-middleware) pre-configured. You can add your own routing rules to `build/dev-server.js` to proxy certain requests to an existing backend server. Or, if you are using Express yourself, you can simply copy the middleware configuration.
55+
- The dev server is simply an [Express](http://expressjs.com/) server with [webpack-dev-middleware](https://github.com/webpack/webpack-dev-middleware) and [webpack-hot-middleware](https://github.com/glenjamin/webpack-hot-middleware) pre-configured. You can add your own routing rules to `build/dev-server.js` to proxy certain requests to an existing backend server. Or, if you are using Express yourself, you can simply copy the middleware configuration, but **make sure to add them only in development mode!**
5656

5757
- For unit testing:
5858

template/build/dev-server.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@ var config = require('./webpack.dev.conf')
66
var app = express()
77
var compiler = webpack(config)
88

9+
// handle fallback for HTML5 history API
10+
app.use(require('connect-history-api-fallback')())
11+
12+
// serve webpack bundle output
913
app.use(require('webpack-dev-middleware')(compiler, {
1014
noInfo: true,
1115
publicPath: config.output.publicPath
1216
}))
1317

18+
// enable hot-reload and state-preserving
19+
// compilation error display
1420
app.use(require('webpack-hot-middleware')(compiler))
1521

16-
app.get('*', function(req, res) {
17-
res.sendFile(path.join(__dirname, 'index.html'))
18-
})
19-
2022
app.listen(8080, 'localhost', function(err) {
2123
if (err) {
2224
console.log(err)

template/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"babel-preset-es2015": "^6.0.0",
2121
"babel-preset-stage-2": "^6.0.0",
2222
"babel-runtime": "^5.8.0",
23+
"connect-history-api-fallback": "^1.1.0",
2324
"css-loader": "^0.23.0",
2425
"eslint": "^1.10.3",
2526
"eslint-friendly-formatter": "^1.2.2",

0 commit comments

Comments
 (0)