-
Notifications
You must be signed in to change notification settings - Fork 49
/
fastboot-server.js
57 lines (45 loc) · 1.66 KB
/
fastboot-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const fs = require('fs');
const express = require('express');
const cluster = require('express-cluster');
const fastbootMiddleware = require('fastboot-express-middleware');
const staticGzip = require('express-serve-static-gzip');
const sabayon = require('express-sabayon');
const assetPath = 'tmp/deploy-dist'
const port = process.env.PORT || 3000;
// eslint-disable-next-line no-console
console.log('Booting Ember app...');
try {
fs.accessSync(assetPath, fs.F_OK);
} catch (e) {
// eslint-disable-next-line no-console
console.error(`The asset path ${assetPath} does not exist.`);
process.exit(1);
}
// FastFail™: this is not mandatory; the first call to visit would
// also boot the app anyway. This is just to provide useful feedback
// instead of booting a server that keeps serving 500.
//
// Note that Application#buildApp is still a private API atm, so it might
// go through more churn in the near term.
// eslint-disable-next-line no-console
console.log('Ember app booted successfully.');
cluster(function() {
let app = express();
let fastboot = fastbootMiddleware(assetPath);
if (assetPath) {
app.get('/', fastboot);
app.use(staticGzip(assetPath));
app.use(express.static(assetPath));
}
app.get(sabayon.path, sabayon.middleware());
app.get('/*', fastboot);
let listener = app.listen(port, function() {
let host = listener.address().address;
let port = listener.address().port;
let family = listener.address().family;
if (family === 'IPv6') { host = '[' + host + ']'; }
// eslint-disable-next-line no-console
console.log('Ember FastBoot running at http://' + host + ":" + port);
});
}, { verbose: true });