Skip to content
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

[WIP] FastBoot compatibility #819

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Ember from 'ember';
import FastbootUtils from '../mixins/fastboot-utils';

const { observer } = Ember;

export default Ember.Controller.extend({
export default Ember.Controller.extend(FastbootUtils, {

searchController: Ember.inject.controller('search'),

flashError: null,
Expand All @@ -11,8 +13,10 @@ export default Ember.Controller.extend({

init() {
this._super(...arguments);
Ember.$(document).on('keypress', this.handleKeyPress.bind(this));
Ember.$(document).on('keydown', this.handleKeyPress.bind(this));
if (this.get('isNotFastBoot')) {
Ember.$(window.document).on('keypress', this.handleKeyPress.bind(this));
Ember.$(window.document).on('keydown', this.handleKeyPress.bind(this));
}
},

// Gets the human-readable string for the virtual-key code of the
Expand Down Expand Up @@ -52,17 +56,23 @@ export default Ember.Controller.extend({
},

willDestroy() {
Ember.$(document).off('keypress');
Ember.$(document).off('keydown');
if (this.get('isNotFastBoot')) {
Ember.$(window.document).off('keypress');
Ember.$(window.document).off('keydown');
}
},

stepFlash() {
this.set('flashError', this.get('nextFlashError'));
this.set('nextFlashError', null);
this.setProperties({
'flashError': this.get('nextFlashError'),
'nextFlashError': null
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is that related to fastboot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related. I just grouped couple of individual set calls. Should've probably kept in a different commit.

},

_scrollToTop() {
window.scrollTo(0, 0);
if (this.get('isNotFastBoot')) {
window.scrollTo(0, 0);
}
},

// TODO: remove observer & DOM mutation in controller..
Expand Down
20 changes: 20 additions & 0 deletions app/mixins/fastboot-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Ember from 'ember';

const { computed, inject: { service } } = Ember;

export default Ember.Mixin.create({

fastboot: service(),

isNotFastBoot: computed.not('fastboot.isFastBoot'),

appURL: computed(function() {
let url = '';
if (this.get('fastboot.isFastBoot')) {
let protocol = this.get('fastboot.request.protocol');
let host = this.get('fastboot.request.host');
url = `${protocol}://${host}`;
}
return url;
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment here might be valuable to understand why we need this

});
7 changes: 5 additions & 2 deletions app/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Ember from 'ember';
import ajax from 'ic-ajax';
import FastbootUtils from '../mixins/fastboot-utils';

export default Ember.Route.extend({
export default Ember.Route.extend(FastbootUtils, {
headTags: [{
type: 'meta',
attrs: {
Expand All @@ -17,7 +18,9 @@ export default Ember.Route.extend({
}
}

return ajax('/summary').then((data) => {
let summaryURL = `${this.get('appURL')}/summary`;

return ajax(summaryURL).then((data) => {
addCrates(this.store, data.new_crates);
addCrates(this.store, data.most_downloaded);
addCrates(this.store, data.just_updated);
Expand Down
7 changes: 5 additions & 2 deletions app/routes/logout.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import Ember from 'ember';
import fetch from 'fetch';
import FastbootUtils from '../mixins/fastboot-utils';

export default Ember.Route.extend(FastbootUtils, {

export default Ember.Route.extend({
activate() {
Ember.$.getJSON('/logout', () => {
fetch(`${this.get('appURL')}/logout`, () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably use ajax() for consistency for now

Ember.run(() => {
this.session.logoutUser();
this.transitionTo('index');
Expand Down
4 changes: 4 additions & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ module.exports = function(environment) {
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},

fastboot: {
hostWhitelist: ['crates.io', /^localhost:\d+$/]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add localhost only in dev mode?

}
};

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"ember-cli-clipboard": "^0.7.0",
"ember-cli-dependency-checker": "^2.0.1",
"ember-cli-eslint": "^4.0.0",
"ember-cli-fastboot": "^1.0.0-rc.5",
"ember-cli-htmlbars": "^2.0.2",
"ember-cli-htmlbars-inline-precompile": "^0.4.3",
"ember-cli-ic-ajax": "1.0.0",
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/mixins/fastboot-utils-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';
import FastbootUtilsMixin from 'cargo/mixins/fastboot-utils';
import { module, test } from 'qunit';

module('Unit | Mixin | fastboot utils');

// Replace this with your real tests.
test('it works', function(assert) {
let FastbootUtilsObject = Ember.Object.extend(FastbootUtilsMixin);
let subject = FastbootUtilsObject.create();
assert.ok(subject);
});
103 changes: 97 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1772,7 +1772,7 @@ compressible@~2.0.8:
dependencies:
mime-db ">= 1.27.0 < 2"

compression@^1.4.4:
compression@^1.4.4, compression@^1.6.2:
version "1.6.2"
resolved "https://registry.yarnpkg.com/compression/-/compression-1.6.2.tgz#cceb121ecc9d09c52d7ad0c3350ea93ddd402bc3"
dependencies:
Expand Down Expand Up @@ -1849,6 +1849,10 @@ [email protected]:
version "0.3.1"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"

cookie@^0.2.3:
version "0.2.4"
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.2.4.tgz#a8c155aa7b9b2cf2c4d32ebc7b9a0aa288ccc6bd"

copy-dereference@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/copy-dereference/-/copy-dereference-1.0.0.tgz#6b131865420fd81b413ba994b44d3655311152b6"
Expand All @@ -1865,6 +1869,12 @@ core-object@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/core-object/-/core-object-1.1.0.tgz#86d63918733cf9da1a5aae729e62c0a88e66ad0a"

core-object@^2.0.5:
version "2.1.1"
resolved "https://registry.yarnpkg.com/core-object/-/core-object-2.1.1.tgz#4b7a5f1edefcb1e6d0dcb58eab1b9f90bfc666a8"
dependencies:
chalk "^1.1.3"

core-object@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/core-object/-/core-object-3.1.3.tgz#df399b3311bdb0c909e8aae8929fc3c1c4b25880"
Expand Down Expand Up @@ -2156,6 +2166,32 @@ ember-cli-eslint@^4.0.0:
rsvp "^3.2.1"
walk-sync "^0.3.0"

ember-cli-fastboot@^1.0.0-rc.5:
version "1.0.0-rc.5"
resolved "https://registry.yarnpkg.com/ember-cli-fastboot/-/ember-cli-fastboot-1.0.0-rc.5.tgz#4f1a5919f1c6bf00850c8412669510fe642b77c3"
dependencies:
broccoli-concat "^3.2.2"
broccoli-funnel "^1.2.0"
broccoli-merge-trees "^1.1.1"
broccoli-plugin "^1.2.1"
broccoli-stew "^1.2.0"
chalk "^1.1.3"
compression "^1.6.2"
core-object "^2.0.5"
debug "^2.2.0"
ember-cli-babel "^5.1.7"
ember-cli-version-checker "^1.3.1"
exists-sync "0.0.4"
express "^4.8.5"
fastboot "1.0.0-rc.6"
fastboot-express-middleware "1.0.0-rc.7"
json-stable-stringify "^1.0.1"
lodash.defaults "^4.0.1"
lodash.uniq "^4.2.0"
md5-hex "^1.3.0"
rsvp "^3.0.16"
silent-error "^1.0.0"

ember-cli-get-component-path-option@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ember-cli-get-component-path-option/-/ember-cli-get-component-path-option-1.0.0.tgz#0d7b595559e2f9050abed804f1d8eff1b08bc771"
Expand Down Expand Up @@ -2388,7 +2424,7 @@ ember-cli-valid-component-name@^1.0.0:
dependencies:
silent-error "^1.0.0"

ember-cli-version-checker@^1.0.2, ember-cli-version-checker@^1.1.4, ember-cli-version-checker@^1.1.6, ember-cli-version-checker@^1.1.7, ember-cli-version-checker@^1.2.0:
ember-cli-version-checker@^1.0.2, ember-cli-version-checker@^1.1.4, ember-cli-version-checker@^1.1.6, ember-cli-version-checker@^1.1.7, ember-cli-version-checker@^1.2.0, ember-cli-version-checker@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/ember-cli-version-checker/-/ember-cli-version-checker-1.3.1.tgz#0bc2d134c830142da64bf9627a0eded10b61ae72"
dependencies:
Expand Down Expand Up @@ -2974,7 +3010,11 @@ expand-tilde@^1.2.2:
dependencies:
os-homedir "^1.0.1"

express@^4.10.7, express@^4.12.3:
[email protected]:
version "0.0.4"
resolved "https://registry.yarnpkg.com/express-cluster/-/express-cluster-0.0.4.tgz#7aa5c39779bbc7550a30525d02b4c022e40b8798"

express@^4.10.7, express@^4.12.3, express@^4.13.3, express@^4.8.5:
version "4.15.3"
resolved "https://registry.yarnpkg.com/express/-/express-4.15.3.tgz#bab65d0f03aa80c358408972fc700f916944b662"
dependencies:
Expand Down Expand Up @@ -3068,6 +3108,30 @@ fast-sourcemap-concat@^1.0.1:
source-map "^0.4.2"
source-map-url "^0.3.0"

[email protected]:
version "1.0.0-rc.7"
resolved "https://registry.yarnpkg.com/fastboot-express-middleware/-/fastboot-express-middleware-1.0.0-rc.7.tgz#285dee01734d40bafe983cefb63e7df0c680f282"
dependencies:
chalk "^1.1.3"
fastboot "^1.0.0-rc.3"

[email protected], fastboot@^1.0.0-rc.3:
version "1.0.0-rc.6"
resolved "https://registry.yarnpkg.com/fastboot/-/fastboot-1.0.0-rc.6.tgz#09af88b41d1b31fda96be425c857e34b2323115b"
dependencies:
chalk "^0.5.1"
cookie "^0.2.3"
debug "^2.1.0"
exists-sync "0.0.3"
express "^4.13.3"
express-cluster "0.0.4"
glob "^4.0.5"
minimist "^1.2.0"
najax "^1.0.1"
rsvp "^3.0.16"
simple-dom "^0.3.0"
source-map-support "^0.4.0"

faye-websocket@~0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.10.0.tgz#4e492f8d04dfb6f89003507f6edbf2d501e7c6f4"
Expand Down Expand Up @@ -3386,6 +3450,15 @@ [email protected], glob@^7.0.4, glob@^7.0.5:
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^4.0.5:
version "4.5.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-4.5.3.tgz#c6cb73d3226c1efef04de3c56d012f03377ee15f"
dependencies:
inflight "^1.0.4"
inherits "2"
minimatch "^2.0.1"
once "^1.3.0"

glob@^5.0.10, glob@^5.0.15:
version "5.0.15"
resolved "https://registry.yarnpkg.com/glob/-/glob-5.0.15.tgz#1bc936b9e02f4a603fcc222ecf7633d30b8b93b1"
Expand Down Expand Up @@ -3929,6 +4002,10 @@ [email protected]:
editions "^1.1.1"
textextensions "1 || 2"

jquery-deferred@^0.3.0:
version "0.3.1"
resolved "https://registry.yarnpkg.com/jquery-deferred/-/jquery-deferred-0.3.1.tgz#596eca1caaff54f61b110962b23cafea74c35355"

jquery@^3.1.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.2.1.tgz#5c4d9de652af6cd0a770154a631bba12b015c787"
Expand Down Expand Up @@ -4193,7 +4270,7 @@ lodash.debounce@^3.1.1:
dependencies:
lodash._getnative "^3.0.0"

lodash.defaults@^4.2.0:
lodash.defaults@^4.0.1, lodash.defaults@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"

Expand Down Expand Up @@ -4391,6 +4468,12 @@ matcher-collection@^1.0.0, matcher-collection@^1.0.1:
dependencies:
minimatch "^3.0.2"

md5-hex@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/md5-hex/-/md5-hex-1.3.0.tgz#d2c4afe983c4370662179b8cad145219135046c4"
dependencies:
md5-o-matic "^0.1.1"

md5-hex@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/md5-hex/-/md5-hex-2.0.0.tgz#d0588e9f1c74954492ecd24ac0ac6ce997d92e33"
Expand Down Expand Up @@ -4583,6 +4666,14 @@ [email protected]:
version "0.0.7"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"

najax@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/najax/-/najax-1.0.3.tgz#11145f4d910446ea661d8ab7fcef53f6ad164ae5"
dependencies:
jquery-deferred "^0.3.0"
lodash.defaultsdeep "^4.6.0"
qs "^6.2.0"

nan@^2.3.0, nan@^2.3.2:
version "2.6.2"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.6.2.tgz#e4ff34e6c95fdfb5aecc08de6596f43605a7db45"
Expand Down Expand Up @@ -5050,7 +5141,7 @@ q@^1.1.2:
version "1.5.0"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.0.tgz#dd01bac9d06d30e6f219aecb8253ee9ebdc308f1"

[email protected], qs@^6.4.0, qs@~6.4.0:
[email protected], qs@^6.2.0, qs@^6.4.0, qs@~6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"

Expand Down Expand Up @@ -5611,7 +5702,7 @@ source-map-support@^0.2.10:
dependencies:
source-map "0.1.32"

source-map-support@^0.4.2:
source-map-support@^0.4.0, source-map-support@^0.4.2:
version "0.4.15"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.15.tgz#03202df65c06d2bd8c7ec2362a193056fef8d3b1"
dependencies:
Expand Down