Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fastboot

ember-fastboot208.1kMIT4.1.5

Library for rendering Ember apps in node.js

ember, fastboot

readme

FastBoot

Greenkeeper badge npm version Build Status

FastBoot is a library for rendering Ember.js applications in Node.js.

For more information about FastBoot, see www.ember-fastboot.com, the Ember CLI addon that's a prerequisite for developing FastBoot apps.

To serve server-rendered versions of your Ember app over HTTP, see the FastBoot App Server.

Usage

const FastBoot = require('fastboot');

let app = new FastBoot({
  distPath: 'path/to/dist',
  // optional boolean flag when set to true does not reject the promise if there are rendering errors (defaults to false)
  resilient: <boolean>,

  // optional function used to generate the set of global properties available within the sandbox, receives default globals
  // and is expected to return an object (the default implementation returns the passed in defaults)
  buildSandboxGlobals(defaultGlobals) {
    return Object.assign({}, defaultGlobals, {
      // additional global properties to define within the sandbox
    });
  },

  // optional number to be provided when using `buildSandboxPerVisit` which defines the queue size for sandboxes.
  // This number should represent your QPS of your service
  maxSandboxQueueSize: <Number> // defaults to 1 if not provided
});

app.visit('/photos', options)
  .then(result => result.html())
  .then(html => res.send(html));

In order to get a dist directory, you will first need to build your Ember application, which packages it up for using in both the browser and in Node.js.

Default globals

FastBoot object will be available to the sandboxed environment. This object has the following form:

FastBoot.require  // provides a mechanism to load additional modules. Note: these modules are only those included in the module whitelist
FastBoot.config   // a function which takes a key, and returns the corresponding fastboot config value
FastBoot.distPath // readOnly accessor that provides the dist path for the current fastboot sandbox

Additional configuration

By default source maps are enabled by the source-maps-support package. Setting an environment variable FASTBOOT_SOURCEMAPS_DISABLE=true will bypass this package effectively disabling source maps support.

app.visit takes a second parameter as options above which a map and allows to define additional optional per request configuration:

  • resilient: whether to reject the returned promise if there is an error during rendering. If not defined, defaults to the app's resilient setting.
  • html: the HTML document to insert the rendered app into. Uses the built app's index.html by default.
  • metadata: per request meta data that is exposed in the app via the fastboot service.
  • shouldRender: boolean to indicate whether the app should do rendering or not. If set to false, it puts the app in routing-only. Defaults to true.
  • disableShoebox: boolean to indicate whether we should send the API data in the shoebox. If set to false, it will not send the API data used for rendering the app on server side in the index.html. Defaults to false.
  • destroyAppInstanceInMs: whether to destroy the instance in the given number of ms. This is a failure mechanism to not wedge the Node process
  • buildSandboxPerVisit: whether to create a new sandbox context per-visit (slows down each visit, but guarantees no prototype leakages can occur), or reuse the existing sandbox (faster per-request, but each request shares the same set of prototypes). Defaults to false. When using this flag, also set maxSandboxQueueSize to represent the QPS of your application so that sandboxes can be queued for next requests. When not provided, it defaults to storing only one sandbox

Build Your App

To get your Ember.js application ready to both run in your user's browsers and run inside the FastBoot environment, run the Ember CLI build command:

$ ember build --environment production

(You will need to have already set up the ember-cli-fastboot addon. For more information, see the FastBoot quickstart.)

Once this is done, you will have a dist directory that contains the multi-environment build of your app.

Run the command to install run time node modules:

$ cd dist/
$ npm install

Upload the dist/ folder including node_modules to your FastBoot server.

Command Line

You can start a simple HTTP server that responds to incoming requests by rendering your Ember.js application using the FastBoot App Server

Debugging

Run fastboot with the DEBUG environment variable set to fastboot:* for detailed logging.

Result

The result from fastboot is a Result object that has the following API:

type DOMContents = () => {
  /**
    The `<head>` contents generated by the visit.
  */
  head: string;

  /**
    The `<body>` contents generated by the visit.
  */
  body: string;
}

interface FastBootVisitResult {
  /**
    The serialized DOM contents after completing the `visit` request.

    Note: this combines the `domContents.head` and `domContents.body`.
  */
  html(): string;

  domContents(): DOMContents

  analytics: {
    /**
     * Boolean to know if the request used a prebuilt sandbox
     */
    usedPrebuiltSandbox: <Boolean>
  }
}

The Shoebox

You can pass application state from the FastBoot rendered application to the browser rendered application using a feature called the "Shoebox". This allows you to leverage server API calls made by the FastBoot rendered application on the browser rendered application. Thus preventing you from duplicating work that the FastBoot application is performing. This should result in a performance benefit for your browser application, as it does not need to issue server API calls whose results are available from the Shoebox.

The contents of the Shoebox are written to the HTML as strings within <script> tags by the server rendered application, which are then consumed by the browser rendered application.

This looks like:

<script type="fastboot/shoebox" id="shoebox-main-store">
{"data":[{"attributes":{"name":"AEC Professionals"},"id":106,"type":"audience"},
{"attributes":{"name":"Components"},"id":111,"type":"audience"},
{"attributes":{"name":"Emerging Professionals"},"id":116,"type":"audience"},
{"attributes":{"name":"Independent Voters"},"id":2801,"type":"audience"},
{"attributes":{"name":"Members"},"id":121,"type":"audience"},
{"attributes":{"name":"Partners"},"id":126,"type":"audience"},
{"attributes":{"name":"Prospective Members"},"id":131,"type":"audience"},
{"attributes":{"name":"Public"},"id":136,"type":"audience"},
{"attributes":{"name":"Staff"},"id":141,"type":"audience"},
{"attributes":{"name":"Students"},"id":146,"type":"audience"}]}
</script>

changelog

v3.1.2 (2020-10-29)

:bug: Bug Fix

  • #281 Ensure extraneous files are not published. (@rwjblue)

Committers: 1

v3.1.1 (2020-10-23)

:bug: Bug Fix

:house: Internal

Committers: 2

v3.1.0 (2020-05-26)

:rocket: Enhancement

  • #272 Introduce html oriented manifest format (introduces better Embroider interop) (@thoov)

Committers: 1

Must provide GITHUB_AUTH

v3.0.2 (2020-03-24)

:rocket: Enhancement

  • #262 Add sandbox queue management when using buildSandboxPerVisit (@kratiahuja)

Committers: 1

v3.0.1 (2020-03-12)

:rocket: Enhancement

  • #262 Improve performance when using new sandbox per visit by building sandbox after the request (@kratiahuja)

Committers: 1

v3.0.0 (2020-01-31)

:boom: Breaking Change

:rocket: Enhancement

  • #252 Expose option to allow a new sandbox per visit (@rwjblue)

:house: Internal

  • #259 Update various dependencies to latest versions. (@rwjblue)

Committers: 1

v3.0.0-beta.3 (2019-11-01)

:bug: Bug Fix

Committers: 1

v3.0.0-beta.2 (2019-11-01)

:boom: Breaking Change

  • #247 Remove najax from default set of sandbox globals. (@rwjblue)

:rocket: Enhancement

  • #245 Refactor sandboxGlobals -> buildSandboxGlobals (@rwjblue)

:house: Internal

Committers: 1

v3.0.0-beta.1 (2019-10-30)

:boom: Breaking Change

:rocket: Enhancement

:bug: Bug Fix

  • #227 Restore allowing fallback require from working directory (@xg-wang)
  • #219 Fix an incorrect debug() call (@CvX)

:memo: Documentation

:house: Internal

Committers: 5

FastBoot Changelog

v2.0.0 (2018-12-10)

:boom: Breaking Change

:rocket: Enhancement

:bug: Bug Fix

:memo: Documentation

:house: Internal

Committers: 5

1.2.0

  • Add support for setting attributes on the <html> element (e.g. <html lang="fr">).

1.1.4-beta.1

  • Enable rehydration from glimmer-vm as opt-in

1.1.3

  • Add markers before and after the body to be able to remove rootless apps

1.1.2

  • Adds API to allow chunking shoebox responses for better performance.

1.1.1

  • Implement unknownProperty in FastbootHeaders to prevent users mistakenly use Ember.get(headers, headerName)

1.1.0

  • Add the ability to support configuration for multiple namespaces to FastBoot.config.

1.0.0-rc.3

  • Remove Node 0.12 support.

1.0.0-rc.2

  • Set the entry point to the built cjs

1.0.0-beta.5

  • Only access instance.getURL if the instance has booted
  • Exclude test files from npm package

1.0.0-beta.4

  • najax dependency updated to 0.7.0, which now handle nested query params
  • Don't obscure errors during instance creation
  • Made request compatible with nodejs' ClientRequest instances

1.0.0-beta.3

  • Responses with status codes 204 or 3xx no longer return the rendered EmberApp
  • Error message for fastboot.request.host now returns the Host header
  • najax dependency updated to 0.6.0, which now handles gzip responses

1.0.0-beta.2

  • Adds support for the "shoebox"‑a place to put data that should be shared from the server-rendered app to the browser-rendered version.

1.0.0-beta.1

  • This version is a significant change from previous versions.
  • Responsibility for serving HTTP requests has been extracted to the fastboot-express-middleware and fastboot-app-server repositories.
  • The name of this project has been changed to reflect the reduction in responsibilities: it is now just fastboot, a library for rendering Ember apps on the server, instead of fastboot-app-server.
  • The minimum required Node version is now v4. Support for 0.12 will be added later via transpiling.
  • Adds a resilient mode, where errors during rendering are suppressed and a blank HTML page is returned instead.
  • JSHint has been added to the automated tests.
  • Calling visit() returns a Result object that encapsulates the rendered result.

0.7.3

  • Application config is now stored in the built application's package.json. This allows turning the storeConfigInMeta back on for FastBoot apps.
  • Setting the document's title via document.title is deprecated. Use the ember-cli-head addon instead.

0.7.2

  • The HTTP response object is now exposed to the FastBoot service.

0.7.1

  • Fixes an issue where requiring built-in modules via FastBoot.require() wouldn't work.

0.7.0

  • Removes the contextify dependency. This should significantly improve install speed and platform compatibility, at the expense of dropping support for Node 0.10.
  • Improves compatibility of the request headers object with the Headers specification.

0.6.2

  • Adds the ability for the FastBoot service to defer rendering the response by providing a promise.

0.6.0

  • Adds hot reloading of app.
  • Fixes an issue where the console global was not available inside the FastBoot sandbox.
  • Makes incoming HTTP request available to the Ember app.