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

Expose FastBoot service #79

Closed
tomdale opened this issue Dec 19, 2015 · 6 comments
Closed

Expose FastBoot service #79

tomdale opened this issue Dec 19, 2015 · 6 comments

Comments

@tomdale
Copy link
Contributor

tomdale commented Dec 19, 2015

I wanted to jot down some thoughts about how we expose FastBoot functionality and additional data into Ember apps. The idea is pretty simple: expose a fastboot service that can house whatever APIs we need to expose to app and addon developers over time.

fastboot Service

Inject it like any service:

import inject from "ember-service/inject";

export default Route.extend({
  fastboot: inject(),

  init() {
    let fastboot = this.get('fastboot');
  }
});

Environment Detection

export default Service.extend({
  fastboot: inject(),
  matchMedia(query) {
    if (this.get('fastboot.isFastBoot')) {
      return false;
    } else {
      return window.matchMedia(query).matches;
    }
  }
});

Cookies

Cookies sent by the requester's browser.

export default Service.extend({
  fastboot: inject(),
  isAuthorized() {
    let cookies = this.get('fastboot.cookies');
    return this.verifyAuthToken(cookies.authToken);
  }
});

Headers

Headers attached to the HTTP request for this route.

export default Service.extend({
  fastboot: inject(),
  isAuthorized() {
    let headers = this.get('fastboot.headers');
    return this.verifyAuthToken(headers['X-Auth-Token']);
  }
});
@ef4
Copy link
Contributor

ef4 commented Dec 19, 2015

Would this be a service in core Ember or in the fastboot addon?

Because I can imagine a lot of addons that want to check isFastBoot without forcing a dependency on the fastboot addon.

@tomdale
Copy link
Contributor Author

tomdale commented Dec 19, 2015

@ef4: In the FastBoot addon. I'm thinking about proposing an "optional" flag for service injections so they don't blow up if not available:

  fastboot: inject({ optional: true })

@ef4
Copy link
Contributor

ef4 commented Dec 19, 2015

Optional injection would be great.

@rwjblue
Copy link
Member

rwjblue commented Dec 19, 2015

I like the idea of a service, but I believe we will still need something available at module eval time (service is only useful at runtime from an object instantiated by the container).

@tomdale
Copy link
Contributor Author

tomdale commented Dec 19, 2015

@rwjblue Can you say more about the evaluation-time use case?

@tomdale tomdale mentioned this issue Jan 27, 2016
38 tasks
@marcoow
Copy link
Contributor

marcoow commented Feb 17, 2016

I guess it would make sense to have a cookies service that abstract all interactions with cookies (as sketched in #120) so that the app can always use the same mechanism to read/write cookies regardless of whether it's running in the browser or in the fastboot env?

@tomdale tomdale closed this as completed Apr 27, 2016
xg-wang pushed a commit to xg-wang/ember-cli-fastboot that referenced this issue Nov 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants