Skip to content

Commit

Permalink
feat: add invalidate endpoint (#2493)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuta Hiroto <[email protected]>
  • Loading branch information
EslamHiko and hiroppy authored Apr 15, 2020
1 parent 0e9bffb commit 89ffb86
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Server {
this.setupDevMiddleware();

// set express routes
routes(this.app, this.middleware, this.options);
routes(this);

// Keep track of websocket proxies for external websocket upgrade.
this.websocketProxies = [];
Expand Down
11 changes: 10 additions & 1 deletion lib/utils/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ const { join } = require('path');

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

function routes(app, middleware, options) {
function routes(server) {
const app = server.app;
const middleware = server.middleware;
const options = server.options;

app.get('/__webpack_dev_server__/live.bundle.js', (req, res) => {
res.setHeader('Content-Type', 'application/javascript');

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

app.get('/invalidate', (_req, res) => {
server.invalidate();
res.end();
});

app.get('/webpack-dev-server', (req, res) => {
res.setHeader('Content-Type', 'text/html');

Expand Down
4 changes: 4 additions & 0 deletions test/server/utils/routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ describe('routes util', () => {
});
});

it('GET request to invalidate endpoint', (done) => {
req.get('/invalidate').expect(200, done);
});

it('should handles GET request to live html', (done) => {
req.get('/webpack-dev-server/').then(({ res }) => {
expect(res.headers['content-type']).toEqual('text/html');
Expand Down

0 comments on commit 89ffb86

Please sign in to comment.