Skip to content

Commit f67d7a0

Browse files
committed
Merge remote-tracking branch 'local/fastboot-app-server/master'
2 parents 2bee927 + 117a9fe commit f67d7a0

44 files changed

Lines changed: 262050 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/**
2+
test/fixtures/**
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
module.exports = {
3+
parserOptions: {
4+
ecmaVersion: 2017,
5+
},
6+
extends: ['eslint:recommended', 'plugin:node/recommended'],
7+
plugins: ['node'],
8+
env: {
9+
node: true,
10+
es6: true,
11+
},
12+
overrides: [
13+
{
14+
files: ['test/**/*-test.js'],
15+
env: {
16+
mocha: true,
17+
},
18+
extends: ['plugin:mocha/recommended'],
19+
plugins: ['mocha'],
20+
},
21+
]
22+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [10.x, 12.x, 14.x]
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- uses: actions/setup-node@v1
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- run: yarn install --frozen-lockfile
24+
- run: yarn test
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.eslintcache
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// set the NODE_ENV to test if not already set, NODE_ENV=test changes the default worker count to 1
2+
process.env.NODE_ENV = process.env.NODE_ENV || 'test';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.gitignore
2+
.eslintcache
3+
.eslintignore
4+
.eslintrc.js
5+
.travis.yml
6+
test/
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## v3.0.0 (2020-10-26)
2+
3+
#### :boom: Breaking Change
4+
* [#124](https://github.com/ember-fastboot/fastboot-app-server/pull/124) Update FastBoot v3 ([@bobisjan](https://github.com/bobisjan))
5+
* [#123](https://github.com/ember-fastboot/fastboot-app-server/pull/123) Drop Node 8 and 13 support ([@bobisjan](https://github.com/bobisjan))
6+
7+
#### :rocket: Enhancement
8+
* [#120](https://github.com/ember-fastboot/fastboot-app-server/pull/120) Remove legacy Node.js support leftovers ([@bobisjan](https://github.com/bobisjan))
9+
* [#96](https://github.com/ember-fastboot/fastboot-app-server/pull/96) Expose `distPath` on `reload` event ([@nathanhammond](https://github.com/nathanhammond))
10+
11+
#### :memo: Documentation
12+
* [#49](https://github.com/ember-fastboot/fastboot-app-server/pull/49) Avoid `server.js` naming conflict ([@oskarrough](https://github.com/oskarrough))
13+
* [#79](https://github.com/ember-fastboot/fastboot-app-server/pull/79) Adds notes to readme about overriding the workerCount ([@Duder-onomy](https://github.com/Duder-onomy))
14+
* [#106](https://github.com/ember-fastboot/fastboot-app-server/pull/106) Add link to s3-notifier ([@allthesignals](https://github.com/allthesignals))
15+
* [#115](https://github.com/ember-fastboot/fastboot-app-server/pull/115) Add link to fastboot-gcloud-storage-notifier in README ([@YoranBrondsema](https://github.com/YoranBrondsema))
16+
* [#114](https://github.com/ember-fastboot/fastboot-app-server/pull/114) Add link to fastboot-gcloud-storage-downloader in README ([@YoranBrondsema](https://github.com/YoranBrondsema))
17+
* [#122](https://github.com/ember-fastboot/fastboot-app-server/pull/122) Update README.md ([@wagenet](https://github.com/wagenet))
18+
19+
#### :house: Internal
20+
* [#128](https://github.com/ember-fastboot/fastboot-app-server/pull/128) Update linting setup ([@rwjblue](https://github.com/rwjblue))
21+
* [#129](https://github.com/ember-fastboot/fastboot-app-server/pull/129) Update mocha to latest. ([@rwjblue](https://github.com/rwjblue))
22+
* [#127](https://github.com/ember-fastboot/fastboot-app-server/pull/127) Update dependencies to latest. ([@rwjblue](https://github.com/rwjblue))
23+
* [#126](https://github.com/ember-fastboot/fastboot-app-server/pull/126) Migrate to GitHub Actions. ([@rwjblue](https://github.com/rwjblue))
24+
* [#125](https://github.com/ember-fastboot/fastboot-app-server/pull/125) Add release automation. ([@rwjblue](https://github.com/rwjblue))
25+
* [#121](https://github.com/ember-fastboot/fastboot-app-server/pull/121) Migrate to ESLint ([@bobisjan](https://github.com/bobisjan))
26+
27+
#### Committers: 8
28+
- Greg Larrenaga ([@Duder-onomy](https://github.com/Duder-onomy))
29+
- Jan Bobisud ([@bobisjan](https://github.com/bobisjan))
30+
- Matt Gardner ([@allthesignals](https://github.com/allthesignals))
31+
- Nathan Hammond ([@nathanhammond](https://github.com/nathanhammond))
32+
- Oskar ([@oskarrough](https://github.com/oskarrough))
33+
- Peter Wagenet ([@wagenet](https://github.com/wagenet))
34+
- Robert Jackson ([@rwjblue](https://github.com/rwjblue))
35+
- Yoran Brondsema ([@YoranBrondsema](https://github.com/YoranBrondsema))
36+
37+
### 1.1.2-beta.1
38+
39+
* Bump fastboot version to allow opting into rehydration.
40+
41+
### 1.1.0
42+
43+
* README updates
44+
* Bumping version of `base-auth` to 2.0.0
45+
* Bumping version of `fastboot` and `fastboot-express-middleware` to 1.1.0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
## Ember FastBoot App Server
2+
3+
The FastBoot App Server is an application server for hosting Ember
4+
FastBoot apps. It manages downloading the Ember app, starting multiple
5+
HTTP server processes, and detecting when new versions of the
6+
application have been deployed.
7+
8+
FastBoot allows Ember apps to be rendered on the server, to support
9+
things like search crawlers and clients without JavaScript. For more
10+
information about FastBoot, see
11+
[FastBoot website][fastboot].
12+
13+
[fastboot]: https://www.ember-fastboot.com
14+
15+
## Extensibility
16+
17+
The App Server is designed to be flexible and extensible enough to run
18+
in whatever environment you want to use to host FastBoot apps. In
19+
particular, you can provide a custom:
20+
21+
* *Downloader*, to control how app builds gets downloaded
22+
* *Notifier*, to control how new versions of the build are detected
23+
* *HTTP Server*, to use whatever stack you prefer for serving HTTP
24+
requests in Node.js
25+
26+
## Requirements
27+
28+
FastBoot App Server requires Node.js v10 or later.
29+
30+
## Quick Start
31+
32+
Put the following in a `fastboot-server.js` file:
33+
34+
```js
35+
const FastBootAppServer = require('fastboot-app-server');
36+
37+
const MY_GLOBAL = 'MY GLOBAL';
38+
39+
let server = new FastBootAppServer({
40+
distPath: 'dist',
41+
gzip: true, // Optional - Enables gzip compression.
42+
host: '0.0.0.0', // Optional - Sets the host the server listens on.
43+
port: 4000, // Optional - Sets the port the server listens on (defaults to the PORT env var or 3000).
44+
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"
45+
return Object.assign({}, defaultGlobals, { GLOBAL_VALUE: MY_GLOBAL });
46+
},
47+
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.
48+
});
49+
50+
server.start();
51+
```
52+
53+
Configure `distPath` to point to the `dist` directory you upload to
54+
your server. (See [Application Builds](#application-builds) below.)
55+
56+
Run the server file:
57+
58+
```
59+
$ PORT=8000 node fastboot-server.js
60+
```
61+
62+
This will start an HTTP server on port 8000. To stop the server, type
63+
`Ctrl-C`.
64+
65+
NOTE: If you want to continue running `ember serve` in development, name the file `fastboot-server.js` instead.
66+
67+
## Application Builds
68+
69+
When you build an Ember.js app via `ember build`, it will build the app
70+
for production and, by default, put the resulting files in your
71+
application's `dist` directory.
72+
73+
## Clustering
74+
75+
Because Node.js is single-threaded, you must run multiple processes to
76+
take advantage of multi-core systems. FastBoot App Server takes
77+
advantage of Node's clustering support out of the box, automatically
78+
spawning one worker HTTP server per core. You can override this via `options.workerCount`.
79+
80+
The app server will automatically spawn a new worker if one dies while
81+
handling a request. When a new application deploy is detected, workers
82+
will automatically reload with the newest version.
83+
84+
## Custom HTTP Server
85+
You can customize HTTP server (add middlewares, subdomains, etc.), either directly:
86+
```js
87+
// start.js
88+
const FastBootAppServer = require('fastboot-app-server');
89+
const ExpressHTTPServer = require('fastboot-app-server/src/express-http-server');
90+
91+
const httpServer = new ExpressHTTPServer(/* {options} */);
92+
const app = httpServer.app;
93+
app.use('/api', apiRoutes);
94+
let server = new FastBootAppServer({
95+
httpServer: httpServer
96+
});
97+
98+
server.start();
99+
```
100+
or extend the provided HTTP server and override any methods you need:
101+
```js
102+
// my-custom-express-server.js
103+
const FastBootAppServer = require('fastboot-app-server');
104+
const ExpressHTTPServer = require('fastboot-app-server/src/express-http-server');
105+
106+
class MyCustomExpressServer extends ExpressHTTPServer {
107+
serve(middleware) {
108+
// put your custom code here, don't forget to add fastboot etc.
109+
}
110+
}
111+
// start.js
112+
const MyCustomExpressServer = require('./my-custom-express-server');
113+
const httpServer = new MyCustomExpressServer(/* {options} */);
114+
let server = new FastBootAppServer({
115+
httpServer: httpServer
116+
});
117+
118+
server.start();
119+
```
120+
121+
## Pre and Post FastBoot middleware hooks
122+
123+
If you need something less than a custom server and just want to run some middleware
124+
before or after FastBoot runs, the server provides hooks for you to do so:
125+
126+
```js
127+
// Custom Middlewares
128+
function modifyRequest(req, res, next) { /* do pre-fastboot stuff to `req` */ };
129+
function handleErrors(err, req, res, next) { /* do error recovery stuff */ };
130+
131+
const server = FastBootAppServer({
132+
beforeMiddleware: function (app) { app.use(modifyRequest); },
133+
afterMiddleware: function (app) { app.use(handleErrors); }
134+
})
135+
```
136+
137+
## Downloaders
138+
139+
You can point the app server at a static path that you manage, but that
140+
means taking responsibility for uploading builds to each server
141+
whenever you want to deploy a new version.
142+
143+
Instead, you can provide the app server with a _downloader_, an adapter
144+
that knows how to download the current version of your application.
145+
146+
For example, to use the S3 downloader that downloads a zip file from
147+
AWS S3:
148+
149+
```js
150+
const S3Downloader = require('fastboot-s3-downloader');
151+
const FastBootAppServer = require('fastboot-app-server');
152+
153+
let downloader = new S3Downloader({
154+
bucket: 'S3_BUCKET',
155+
key: 'S3_KEY'
156+
});
157+
158+
let server = new FastBootAppServer({
159+
downloader: downloader
160+
});
161+
162+
server.start();
163+
```
164+
165+
### Available Downloaders
166+
167+
* [fastboot-s3-downloader](https://github.com/ember-fastboot/fastboot-s3-downloader)
168+
* [fastboot-gcloud-storage-downloader](https://github.com/EmberSherpa/fastboot-gcloud-storage-downloader)
169+
170+
### Writing a Downloader
171+
172+
To write your own downloader, construct an object that conforms to the
173+
following interface:
174+
175+
#### `download()`
176+
177+
Returns a promise that resolves to the path to the downloaded `dist`
178+
directory (which does not have to be named `dist`).
179+
180+
Note that `download()` may be called more than once in the lifetime of
181+
an application, if a new version is deployed. Make sure your downloader
182+
cleans up after itself to avoid running out of disk space.
183+
184+
## Notifiers
185+
186+
Once the FastBoot App Server is up and running, it will happily chug
187+
away until the server dies or it reaches the inevitable heat death of the
188+
universe. Before that happens, presumably, you may want to deploy a new
189+
version of your application.
190+
191+
_Notifiers_ are responsible for detecting when a new version of an app
192+
has been deployed and reloading the app server.
193+
194+
For example, here's how to use the S3 notifier, which polls the last
195+
modified date of a file on S3 to detect new versions:
196+
197+
```js
198+
const S3Notifier = require('fastboot-s3-notifier');
199+
const FastBootAppServer = require('fastboot-app-server');
200+
201+
let notifier = new S3Notifier({
202+
bucket: S3_BUCKET,
203+
key: S3_KEY
204+
});
205+
206+
let server = new FastBootAppServer({
207+
notifier: notifier
208+
});
209+
210+
server.start();
211+
```
212+
213+
### Available Notifiers
214+
215+
* [fastboot-s3-notifier](https://github.com/ember-fastboot/fastboot-s3-notifier)
216+
* [fastboot-fs-notifier](https://github.com/iheanyi/fastboot-fs-notifier)
217+
* [fastboot-watch-notifier](https://github.com/pwfisher/fastboot-watch-notifier)
218+
* [fastboot-gcloud-storage-notifier](https://github.com/EmberSherpa/fastboot-gcloud-storage-notifier)
219+
220+
### Writing a Notifier
221+
222+
To write your own notifier, construct an object that conforms to the
223+
following interface:
224+
225+
#### `subscribe(notify)`
226+
227+
The `subscribe()` method on your notifier is passed a `notify` function.
228+
If you detect that a new version of your app has been deployed (whether
229+
via polling or a push notification), call this function to trigger a
230+
reload.
231+
232+
## Basic Authentication
233+
234+
You can enable Basic Authentication by providing `username` and `password` options:
235+
236+
```js
237+
const FastBootAppServer = require('fastboot-app-server');
238+
239+
let server = new FastBootAppServer({
240+
username: 'tomster',
241+
password: 'zoey'
242+
});
243+
```
244+
245+
## Scraper Issues
246+
247+
### Twitter and LinkedIn
248+
249+
As of 2019-06-06, Twitter and LinkedIn's scrapers have a hard time extracting your site's metadata for sharing if `chunkedResponse` is set to `true` in your `server.js` file. Set `chunkedResponse: false` if your meta tags are in place but the [Twitter card validator](https://cards-dev.twitter.com/validator) shows "Card not found" or [LinkedIn's Post Inspector](https://www.linkedin.com/post-inspector/) shows a 500 error.

0 commit comments

Comments
 (0)