-
Notifications
You must be signed in to change notification settings - Fork 159
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
Unify fastboot serving with ember-cli #356
Conversation
This is now ready for review. |
Note to self:
|
index.js
Outdated
// TODO: we can do a smarter reload here by running fs-tree-diff on files loaded | ||
// in sandbox (explore later). | ||
this.ui.writeLine('Reloading FastBoot...'); | ||
this.fastboot.reload({ |
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.
Is fastboot reload
synchronous? If it is asynchronous, we may need to do more work to ensure no requests during this period are served.
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.
It is synchronous. I confirmed that 😄 Though I plan to make it promise friendly when I take a stab at the smarter reload handling.
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.
We can implement the instrumentation
hook (ember-cli@2.13+) and detect the output files that have changed, to see if we need to reload fastboot
here.
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.
Agreed. That will eliminate a lot of boiler plate code that I planned to write :)
fastboot: this.fastboot | ||
}); | ||
|
||
fastbootMiddleware(req, resp, next); |
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.
the conditional on line 160 suggests we only serve fastbootMiddelware
for the first request, subsequent requests will fallback to the else
case.
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.
Yes that is correct (I assume you meant line 158 and not 160). If I understand correctly, FastBoot is only meant for initial requests and that too for the base page request (basically have your app be server side rendered for the initial request). Once the base page request is served, the browser will request for assets which should be served by ember-cli
's asset serving. Same also applies for subsquent page transitions in Ember (for lazy engines/lazy template loading usecase).
Do you think that is a wrong assumption? Is there a usecase that I might have missed?
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.
Do you think that is a wrong assumption? Is there a usecase that I might have missed?
Ya, that isn't quite correct. If a user hard reloads (or issues curl
repeatedly), they should once again get a fastboot rendered page.
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.
@stefanpenner They will get a fastboot rendered page. FastBoot is just responsible for serving the index.html with the rendered content. I did test both use cases on a test app. I am not sure I am following what is not correct.
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.
Your right. for some reason i read line 174 being within the if statement of 161. Not sure how that happened, my bad.
@kratiahuja with this change |
Just spitballing: what if we could skip injected middleware via query params |
index.js
Outdated
// forward the request to the next middleware (example other assets, proxy etc) | ||
next(); | ||
} | ||
}.bind(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.
I think we can use arrow functions instead of .bind(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.
Yeah I totally forgot ember-cli allows arrow functions now. Will update 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.
Updated to use arrow functions.
@mfazekas @danmcclain https://github.com/ember-fastboot/ember-cli-fastboot#double-build-times-and-no-incremental-builds this is how you can run a normal build without removing the ember-cli-fastboot package. |
@kellyselden I was thinking of a way that wouldn't require you to restart the server (and also double build times are going away 🙌 ) |
@mfazekas @danmcclain I agree this is a valid usecase but not scoped to this PR. I want to first get base functionality in and then work on this enhancement and others (see future section). I also like the idea of the query param to switch fastboot serving on/off at run time. I was also thinking of providing it via |
fastboot: this.fastboot | ||
}); | ||
|
||
fastbootMiddleware(req, resp, next); |
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.
Your right. for some reason i read line 174 being within the if statement of 161. Not sure how that happened, my bad.
Tested this PR with cc: @rwjblue |
@rwjblue could you please review this? 😄 |
Awesome work @kratiahuja! I tested this branch in our application as well as in brand new ember app and it works as a charm. 🎉 Looking forward to have this merged and available to users. |
This looks good! |
Is there anything else blocking this PR? |
@bcardarella Nope nothing is blocking this PR except someone reviewing it. I'll ping @rwjblue or someone else again after the ember conference. |
Didn't @stefanpenner already approve? |
@bcardarella Yes but I think @rwjblue also wanted to review before merging. Unfortunately I don't have merge powers so we will have to wait for someone with merge powers to review and merge. |
Bumping this again. @rwjblue could you please review? |
lib/commands/fastboot-build.js
Outdated
@@ -20,7 +20,8 @@ module.exports = { | |||
project: this.project | |||
}); | |||
|
|||
deprecate("Use of ember fastboot:build is deprecated. Please use ember build instead."); | |||
deprecate('ember fastboot:build will be deprecated and removed after FastBoot 1.0 is released.'); |
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 not sure why we need to add this extra deprecation here. It seems like the preexisting one should already cover the case we care about, 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.
Yeah but I just wanted to update the deprecation to say we will be dropping this command too.
lib/commands/fastboot.js
Outdated
var checker = new VersionChecker(this); | ||
var dep = checker.for('ember-cli', 'npm'); | ||
|
||
this.ui.writeWarnLine('`ember fastboot` will no longer work after FastBoot 1.0 is released.'); |
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.
Lets only emit this deprecation when ember-cli is less than 2.12.0-beta.1 (basically the else case of the if
just below).
Only two super minor changes around messaging, then this is good to go... |
@rwjblue This is good to merge now. Travis is 💚 |
Thank you for all your hard work on this @kratiahuja! |
Awesome, thanks indeed! 🎉 |
TL;DR: fixes #274 . This will unblock one of the FastBoot 1.0 blockers.
Motivation
Currently FastBoot provides users to serve the base page and the assets via the
ember fastboot
command. It primarily spins up an express server that is responsible for serving the request with a fastboot replaced base page and serves other assets from disk. However, this is similar to whatember cli
provides viaember serve
. Since we are not the infrastructure provided by ember-cli, development withember fastboot
has become very error prone for various reasons. The PR attempts to resolve those development concerns.How it works
ember-cli@2.12.0-beta.1 and above introduced a public API in ember-cli that allows addons to be responsible for serving the base page and/or assets while still be able to consume the other nice features of
ember serve
. It does so by splitting the task of watching the build and serving assets into different middleware. Infrastructures like FastBoot can then hook a middleware between the watcher and server middleware and be responsible for serving the base page request.If apps are using
ember-cli@2.12.0-beta.1
and above, they will be able to serve fastboot rendered base page usingember serve
and continue using other features ofember serve
. For apps running ember-cli version below 2.12.0-beta.1, they will not be able to useember serve
with FastBoot.With the new serving logic, you can use
curl
withember serve
:curl 'http://localhost:4200/' -H 'Accept: text/html'
This PR does the following:
ember-cli-fastboot
addon to run beforebroccoli-serve-files
addon.broccoli-serve-files
is an in-repo addon in ember-cliserverMiddleware
API ofember-cli
to provide a middleware to usefastboot-express-middleware
when there is a base request.ember fastboot
ember fastboot
Advantages
With using
ember serve
to have FastBoot serve the initial base page request we get the following features for free:ember cli
as it does for vanilla appember serve --proxy=http://localhost:3000
ember-cli
live reload functionality.tmp
directory instead of dist.Deprecation of
ember fastboot
Since this PR does similar to what
ember fastboot --watch --serve-assets
provides, we will be deprecatingember fastboot
command.Future TODOs
Following are the minor enhancements that I would like to fix on after this PR lands. They do not block this PR.
fs-tree-diff
to see if any of the app/vendor files have changed on rebuild and only load it sandbox then.sandboxGlobals
and/or custom sandbox class when serving using FastBoot in development. No one seems to be using this so just added a TODO for now.ember-cli-fastboot
cc: @rwjblue @tomdale @danmcclain @stefanpenner @josemarluedke @arjansingh