-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: add invalidate endpoint #2493
feat: add invalidate endpoint #2493
Conversation
@@ -64,6 +64,10 @@ describe('routes util', () => { | |||
}); | |||
}); | |||
|
|||
it('GET request to invalidate endpoint', (done) => { | |||
req.get('/invalidate').expect(200, done); | |||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will be great to test what we really do invalidate - get stats before do request and do get stats again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't detect any changes in server.middleware
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and server.middleware.context.stats
is always undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange, should be no
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've thought about an Idea maybe we can create an option invalidateCallback
and we create a function that creates a file then delete after confirming that the file exists.
@evilebottnawi what do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad idea, maybe we need fix something in tests, need debug
Codecov Report
@@ Coverage Diff @@
## master #2493 +/- ##
==========================================
- Coverage 93.74% 93.58% -0.17%
==========================================
Files 34 34
Lines 1327 1325 -2
Branches 381 379 -2
==========================================
- Hits 1244 1240 -4
- Misses 81 83 +2
Partials 2 2
Continue to review full report at Codecov.
|
@@ -118,7 +118,7 @@ class Server { | |||
this.setupDevMiddleware(); | |||
|
|||
// set express routes | |||
routes(this.app, this.middleware, this.options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hiroppy To pass the server, so I can call server.invalidate()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm -1 on this change because if you pass this
, we can't understand what variables are used by this function clearly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hiroppy I tried (this.app, this.middleware, this.options, this.invalidate)
and called invalidate()
only but this resulted in 500 "Internal Server Error"
so what about changing this
into server
for better reading ex:
const server = this;
routes(server);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one thing that worked was moving
invalidate(callback) {
if (this.middleware) {
this.middleware.invalidate(callback);
}
}
to routes.js
and make it only accessable via the api call, but that would require adding an option invalidateCallBack
so we can pass it ex:
this.invalidateCallBack = this.options.invalidateCallBack;
// set express routes
routes(this.app, this.middleware, this.options, this.invalidateCallBack);
and in routes.js
function routes(app, middleware, options, invalidateCallBack) {
app.get('/invalidate', (_req, res) => {
if(middleware)
middleware.invalidate(invalidateCallBack)
res.end();
});
}
@@ -118,7 +118,7 @@ class Server { | |||
this.setupDevMiddleware(); | |||
|
|||
// set express routes | |||
routes(this.app, this.middleware, this.options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm -1 on this change because if you pass this
, we can't understand what variables are used by this function clearly.
@hiroppy I think it is normal to pass |
I got it but it's hard to read for me like a black box. |
@hiroppy I think we can do refactor for utils and code for next branch, we have many bad places that we can improve, maybe using destructuring is good idea in many places |
@evilebottnawi Totally agree with you. I'll improve these codes on the next branch. |
/cc @hiroppy |
@@ -30,6 +34,11 @@ function routes(app, middleware, options) { | |||
createReadStream(join(clientBasePath, 'live.html')).pipe(res); | |||
}); | |||
|
|||
app.get('/invalidate', (_req, res) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should better be prefixed with webpack-dev-server
maybe /webpack-dev-server/invalidate
. Otherwise /invalidate
is unusable for the user and apps using /invalidate
in their router break.
For Bugs and Features; did you add new tests?
yes
complete: #1546
Motivation / Use-Case
Breaking Changes
no
Additional Info