Skip to content

Commit 06aee44

Browse files
authored
fix: strip accept header when using history-api-fallback (#98)
1 parent 817a8a8 commit 06aee44

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ If `true`, enables History API Fallback via [`connect-history-api-fallback`](htt
122122

123123
This setting can be handy when using the HTML5 History API; `index.html` page will likely have to be served in place of any 404 responses from the server, specially when developing Single Page Applications.
124124

125+
_Note: The `Accept` header is explicitly stripped from the `/wps` WebSocket path when using `historyFallback`, due to [an issue](https://github.com/shellscape/webpack-plugin-serve/issues/94) with how Firefox and the middleware interact.
126+
125127
### `hmr`
126128
Type: `boolean`<br>
127129
Default: `true`

lib/middleware.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,28 @@ const getBuiltins = (app, options) => {
8888
}
8989
};
9090

91+
const four0four = (fn = () => {}) => {
92+
app.use(async (ctx, next) => {
93+
await next();
94+
if (ctx.status === 404) {
95+
render404(ctx);
96+
fn(ctx);
97+
}
98+
});
99+
};
100+
91101
const historyFallback = () => {
92102
if (options.historyFallback) {
103+
// https://github.com/shellscape/webpack-plugin-serve/issues/94
104+
// When using Firefox, the browser sends an accept header for /wps when using connect-history-api-fallback
105+
app.use(async (ctx, next) => {
106+
if (ctx.path.match(/^\/wps/)) {
107+
const { accept, ...headers } = ctx.request.header;
108+
ctx.request.header = headers; // eslint-disable-line no-param-reassign
109+
}
110+
await next();
111+
});
112+
93113
app.use(convert(historyApiFallback(options.historyFallback)));
94114
}
95115
};
@@ -102,19 +122,8 @@ const getBuiltins = (app, options) => {
102122
}
103123
};
104124

105-
const websocket = () => app.use(wsMiddleware);
106-
107125
const proxy = (...args) => convert(httpProxyMiddleware(...args));
108-
109-
const four0four = (fn = () => {}) => {
110-
app.use(async (ctx, next) => {
111-
await next();
112-
if (ctx.status === 404) {
113-
render404(ctx);
114-
fn(ctx);
115-
}
116-
});
117-
};
126+
const websocket = () => app.use(wsMiddleware);
118127

119128
proxy.skip = true;
120129

0 commit comments

Comments
 (0)