-
-
Notifications
You must be signed in to change notification settings - Fork 797
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
[legacy-framework] Add support for async experimental.initServer()
#2798
Conversation
@g3offrey thank you so much! Upon review, I think we could run initServer just before this line in getServer. What do you think? |
@flybayer Don't worry, I'm glad to contribute to such a project 😄 First, at the moment the With my modification, we can call it once in async getRequestHandler() {
const requestHandler = await this.getServerRequestHandler()
return (
req: IncomingMessage,
res: ServerResponse,
parsedUrl?: UrlWithParsedQuery
) => {
return requestHandler(req, res, parsedUrl)
}
} As now With these modifications, I can implement your solution. What do you think? Do you prefer this way of doing things or the previous one? 😄 Check out the last commit. I hope I am clear enough, that's not easy by text 😅 |
e9f3bd3
to
d24db08
Compare
Hey @g3offrey so sorry for then long delay here. I really appreciate your work on this. I spent some time analyzing this, and I think we were following a constraint that we don't need. I can't see any reason that we have to await initServer before the http server is listening. Because initServer can't change the listening port or anything. So I think we can just add await initServer in getServer without all the other changes. What do you think? And in general, we want to have a solution that minimizes changes since we are a fork of nextjs and merge in the their changes. |
d24db08
to
40c5503
Compare
Hi @flybayer Don't worry, it seems to be a big piece of changes, so I totally understand that it is long to review. I think I implemented it on my latest commit (after reverting previous code). Please check it out and tell me if any changes are required 😄 |
Awesome, thank you so much!! |
experimental.initServer()
experimental.initServer()
experimental.initServer()
Closes: blitz-js/legacy-framework#279
What are the changes and their implications?
I did the solution proposed by @flybayer on the issue blitz-js/legacy-framework#279
To do so I had to load the config before the server is listening. Indeed today, the config loading is done at first on
prepare
method, which is run on the server listening.The
loadConfig
method was private so I had to set it a public 😢Another drawback of this is that the
loadConfig
is now done two times: before the listening and when we callgetServer
(at the listening).I was thinking about two things doing that, moving the
initServer
logic inside aNextServer
method (onServerInit
?), so I can set backloadConfig
as private.Or maybe instead of calling
loadConfig
, I can callgetServer
(setting it public before so) which has aloadConfig
inside of it. This has advantages of preparing theserverPromise
per advance and won't do a duplicate call toloadConfig
.What do you think ? 🤔
(As this is an experimental feature at the moment, we can log a refactoring ticket and do the changes on the future.)
Bug Checklist
Feature Checklist