Skip to content

Commit 111b7eb

Browse files
committed
Auto merge of #1715 - kzys:enable-fastboot, r=jtgeibel
Enable FastBoot Actually, without completely removing jQuery, FastBoot seems working.
2 parents 27bd9a8 + 56f23f1 commit 111b7eb

File tree

16 files changed

+1374
-405
lines changed

16 files changed

+1374
-405
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = {
2929
'.eslintrc.js',
3030
'.template-lintrc.js',
3131
'ember-cli-build.js',
32+
'fastboot.js',
3233
'testem.js',
3334
'blueprints/*/index.js',
3435
'config/**/*.js',

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
release: bin/diesel migration run
2-
web: bin/start-nginx ./target/release/server
2+
web: bin/start-nginx npm run nf -- --procfile foreman-procfile start --raw
33
background_worker: ./target/release/background-worker

app/styles/app.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ body {
3333
@include align-items(center);
3434
}
3535

36-
.ember-application > div {
36+
/* .ember-application is added by Ember after initial rendering */
37+
.ember-application > div,
38+
body > div {
3739
width: 960px;
3840
@media only screen and (max-width: 960px) {
3941
width: 100%;

config/environment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ module.exports = function(environment) {
2222
// Here you can pass flags/options to your application instance
2323
// when it is created
2424
},
25+
fastboot: {
26+
hostWhitelist: ['crates.io', /^localhost:\d+$/, /\.herokuapp\.com$/],
27+
},
2528
};
2629

2730
if (environment === 'development') {

config/nginx.conf.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ http {
6464
proxy_pass http://app_server;
6565
}
6666

67+
# Just in case, only forward "/policies" to Ember for a moment
68+
location = /policies {
69+
proxy_pass http://localhost:9000;
70+
}
71+
6772
location ~ ^/api/v./crates/new$ {
6873
proxy_pass http://app_server;
6974

fastboot.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* eslint-disable no-console */
2+
3+
'use strict';
4+
5+
const fs = require('fs');
6+
const FastBootAppServer = require('fastboot-app-server');
7+
8+
// because fastboot-app-server uses cluster, but it might change in future
9+
const cluster = require('cluster');
10+
11+
class LoggerWithoutTimestamp {
12+
constructor() {
13+
this.prefix = cluster.isMaster ? 'master' : 'worker';
14+
}
15+
writeLine() {
16+
this._write('info', Array.prototype.slice.apply(arguments));
17+
}
18+
19+
writeError() {
20+
this._write('error', Array.prototype.slice.apply(arguments));
21+
}
22+
23+
_write(level, args) {
24+
args[0] = `[${level}][${this.prefix}] ${args[0]}`;
25+
console.log.apply(console, args);
26+
}
27+
}
28+
29+
function writeAppInitializedWhenReady(logger) {
30+
let timeout;
31+
32+
timeout = setInterval(function() {
33+
logger.writeLine('waiting backend');
34+
if (fs.existsSync('/tmp/backend-initialized')) {
35+
logger.writeLine('backend is up. let heroku know the app is ready');
36+
fs.writeFileSync('/tmp/app-initialized', 'hello');
37+
clearInterval(timeout);
38+
} else {
39+
logger.writeLine('backend is still not up');
40+
}
41+
}, 1000);
42+
}
43+
44+
var logger = new LoggerWithoutTimestamp();
45+
46+
let server = new FastBootAppServer({
47+
distPath: 'dist',
48+
port: 9000,
49+
ui: logger,
50+
});
51+
52+
if (!cluster.isWorker) {
53+
writeAppInitializedWhenReady(logger);
54+
}
55+
56+
server.start();

fastboot/initializers/ajax.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
name: 'ajax-service',
3+
initialize() {
4+
// This is to override Fastboot's initializer which prevents ember-fetch from working
5+
// https://github.com/ember-fastboot/ember-cli-fastboot/blob/master/fastboot/initializers/ajax.js
6+
// https://github.com/ember-cli/ember-fetch#ajax-service
7+
},
8+
};

foreman-procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ember: node fastboot.js
2+
api: ./target/release/server

0 commit comments

Comments
 (0)