Skip to content

Commit 89ffb86

Browse files
EslamHikohiroppy
andauthored
feat: add invalidate endpoint (#2493)
Co-authored-by: Yuta Hiroto <[email protected]>
1 parent 0e9bffb commit 89ffb86

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/Server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Server {
118118
this.setupDevMiddleware();
119119

120120
// set express routes
121-
routes(this.app, this.middleware, this.options);
121+
routes(this);
122122

123123
// Keep track of websocket proxies for external websocket upgrade.
124124
this.websocketProxies = [];

lib/utils/routes.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ const { join } = require('path');
55

66
const clientBasePath = join(__dirname, '..', '..', 'client');
77

8-
function routes(app, middleware, options) {
8+
function routes(server) {
9+
const app = server.app;
10+
const middleware = server.middleware;
11+
const options = server.options;
12+
913
app.get('/__webpack_dev_server__/live.bundle.js', (req, res) => {
1014
res.setHeader('Content-Type', 'application/javascript');
1115

@@ -30,6 +34,11 @@ function routes(app, middleware, options) {
3034
createReadStream(join(clientBasePath, 'live.html')).pipe(res);
3135
});
3236

37+
app.get('/invalidate', (_req, res) => {
38+
server.invalidate();
39+
res.end();
40+
});
41+
3342
app.get('/webpack-dev-server', (req, res) => {
3443
res.setHeader('Content-Type', 'text/html');
3544

test/server/utils/routes.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ describe('routes util', () => {
6464
});
6565
});
6666

67+
it('GET request to invalidate endpoint', (done) => {
68+
req.get('/invalidate').expect(200, done);
69+
});
70+
6771
it('should handles GET request to live html', (done) => {
6872
req.get('/webpack-dev-server/').then(({ res }) => {
6973
expect(res.headers['content-type']).toEqual('text/html');

0 commit comments

Comments
 (0)