This guide shows you how to deploy Ember Fastboot apps on Layer0.

This framework has a connector developed for Layer0. See Connectors for more information.

To prepare your Fastboot app for deployment on Layer0, run the following in the root folder of your project:

npm install -g 0/cli
0 init

This will automatically add all of the required dependencies and files to your project. These include:

  • The 0/core package - Allows you to declare routes and deploy your application on Layer0
  • The 0/fastboot package - Provides router middleware that automatically adds Fastboot routes to Layer0 router.
  • The 0/prefetch package - Allows you to configure a service worker to prefetch and cache pages to improve browsing speed
  • The 0/react package - Provides a Prefetch component for prefetching pages
  • routes.js - A default routes file that sends all requests to Fastboot. Update this file to add caching or proxy some URLs to a different origin.
  • sw/service-worker.js - The source code for your service worker, which enables prefetching when running on Layer0.
  • layer0.config.js - Contains configuration options for deploying on Layer0.

To add Layer0 service worker to your app, call the install function from 0/prefetch/window hook when the app first loads. For example, you can alter app/app.js as follows:

import Application from '@ember/application'
import Resolver from 'ember-resolver'
import loadInitializers from 'ember-load-initializers'
import config from './config/environment'

// add this to import Layer0 service worker prefetching functionality
import { install } from '0/prefetch/window'

export default class App extends Application {
  modulePrefix = config.modulePrefix
  podModulePrefix = config.podModulePrefix
  Resolver = Resolver
}

loadInitializers(App, config.modulePrefix)

// add this to install the service worker when your app loads
if (typeof navigator != 'undefined') {
  install()
}

To reduce serverless cold-start times, limit the packages listed in the dependencies section of your package.json to only those packages used at runtime. The 0/fastboot package must also be included in dependencies. Other packages not used at runtime should be included in devDependencies. Only those packages listed in dependencies are deployed to Layer0 along with your application code.

Ember fastboot apps should always have the following in layer0.config.js:

module.exports = {
  connector: '0/fastboot',
  includeNodeModules: true, // this ensures that package.json dependencies are uploaded to the cloud
}

To simulate your app within Layer0 locally, run:

0 dev

To simulate edge caching locally, run:

0 dev --cache

Deploying requires an account on Layer0. Sign up here for free. Once you have an account, you can deploy to Layer0 by running the following in the root folder of your project

0 deploy

See deploying for more information.

Edit this guide on GitHub