Ember FastBoot App Server
fastboot-app-server is a dedicated application server designed for deploying and running Ember FastBoot applications in production environments. It provides robust capabilities for managing the lifecycle of an Ember app, including downloading new builds, automatically scaling across CPU cores using Node.js clustering, and seamlessly detecting and hot-reloading new application versions without downtime. The current stable version is 4.1.4. The project maintains a steady release cadence with frequent patch updates and less frequent major versions, with v4.0.0 released in early 2024. Key differentiators include its built-in extensibility, allowing developers to customize how app builds are downloaded (Downloader), how new versions are detected (Notifier), and even swap out the underlying HTTP server implementation (e.g., using Express) to integrate custom middleware or routing. It aims to simplify the operational aspects of server-side rendering Ember applications.
Common errors
-
Error: Cannot find module 'fastboot-app-server'
cause Attempting to use ES module `import` syntax (`import FastBootAppServer from 'fastboot-app-server'`) in a CommonJS context, or incorrect package installation/path.fixEnsure you are using CommonJS `require()` syntax (`const FastBootAppServer = require('fastboot-app-server');`) if your project is not configured for ESM. Also, verify `fastboot-app-server` is correctly installed in your `node_modules`. -
TypeError: app.buildSandboxGlobals is not a function
cause Calling `buildSandboxGlobals` or similar methods on an incorrect object, or passing an invalid type to the server options.fixEnsure `buildSandboxGlobals` is passed as an option during the `FastBootAppServer` constructor, not called directly. It should be a function that receives `defaultGlobals` and returns an object of additional globals. -
Error: EMFILE: too many open files, watch
cause Node.js file watcher limit reached, often due to many files in the `distPath` or multiple workers monitoring the same directory.fixIncrease your system's `fs.inotify.max_user_watches` limit (Linux) or `kern.maxfiles` (macOS). Alternatively, for very large apps or complex deployments, consider disabling the server's default file watching mechanism if you have an external build deployment strategy.
Warnings
- breaking FastBoot App Server v4.0.0 and above no longer support Node.js v12. Ensure your production environment uses Node.js v14 or later. While the `engines` field in package.json might include Node 12, the official release notes for v4.0.0 explicitly state the removal of Node 12 support.
- breaking Version 4.0.0 removed deprecated implicit injections. Any code relying on these older injection patterns will break.
- gotcha When customizing the HTTP server, the `ExpressHTTPServer` class is imported from `fastboot-app-server/src/express-http-server`. Directly referencing `src` paths can be fragile across minor versions as internal directory structures are not part of the public API and may change.
- gotcha The `distPath` option must correctly point to the compiled `dist` directory of your Ember application. Misconfiguration will lead to the server being unable to locate and serve your application.
Install
-
npm install fastboot-app-server -
yarn add fastboot-app-server -
pnpm add fastboot-app-server
Imports
- FastBootAppServer
import { FastBootAppServer } from 'fastboot-app-server';const FastBootAppServer = require('fastboot-app-server'); - ExpressHTTPServer
const ExpressHTTPServer = require('fastboot-app-server/src/express-http-server'); - MyCustomExpressServer (example)
import { MyCustomExpressServer } from 'my-custom-express-server';class MyCustomExpressServer extends ExpressHTTPServer { /* ... */ }
Quickstart
const FastBootAppServer = require('fastboot-app-server');
const MY_GLOBAL = 'MY GLOBAL';
let server = new FastBootAppServer({
distPath: 'dist',
gzip: true, // Optional - Enables gzip compression.
host: '0.0.0.0', // Optional - Sets the host the server listens on.
port: 4000, // Optional - Sets the port the server listens on (defaults to the PORT env var or 3000).
buildSandboxGlobals(defaultGlobals) { // Optional - Make values available to the Ember app running in the FastBoot server, e.g. "MY_GLOBAL" will be available as "GLOBAL_VALUE"
return Object.assign({}, defaultGlobals, { GLOBAL_VALUE: MY_GLOBAL });
},
log: true, // Optional - Specifies whether the server should use its default request logging. Useful for turning off default logging when providing custom logging middlewares
chunkedResponse: true // Optional - Opt-in to chunked transfer encoding, transferring the head, body and potential shoeboxes in separate chunks. Chunked transfer encoding should have a positive effect in particular when the app transfers a lot of data in the shoebox.
});
server.start();