Skip to content

Commit

Permalink
Auto merge of rust-lang#1715 - kzys:enable-fastboot, r=jtgeibel
Browse files Browse the repository at this point in the history
Enable FastBoot

Actually, without completely removing jQuery, FastBoot seems working.
  • Loading branch information
bors committed Sep 5, 2019
2 parents 27bd9a8 + 56f23f1 commit 111b7eb
Show file tree
Hide file tree
Showing 16 changed files with 1,374 additions and 405 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Expand Up @@ -29,6 +29,7 @@ module.exports = {
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'fastboot.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
Expand Down
2 changes: 1 addition & 1 deletion Procfile
@@ -1,3 +1,3 @@
release: bin/diesel migration run
web: bin/start-nginx ./target/release/server
web: bin/start-nginx npm run nf -- --procfile foreman-procfile start --raw
background_worker: ./target/release/background-worker
4 changes: 3 additions & 1 deletion app/styles/app.scss
Expand Up @@ -33,7 +33,9 @@ body {
@include align-items(center);
}

.ember-application > div {
/* .ember-application is added by Ember after initial rendering */
.ember-application > div,
body > div {
width: 960px;
@media only screen and (max-width: 960px) {
width: 100%;
Expand Down
3 changes: 3 additions & 0 deletions config/environment.js
Expand Up @@ -22,6 +22,9 @@ module.exports = function(environment) {
// Here you can pass flags/options to your application instance
// when it is created
},
fastboot: {
hostWhitelist: ['crates.io', /^localhost:\d+$/, /\.herokuapp\.com$/],
},
};

if (environment === 'development') {
Expand Down
5 changes: 5 additions & 0 deletions config/nginx.conf.erb
Expand Up @@ -64,6 +64,11 @@ http {
proxy_pass http://app_server;
}

# Just in case, only forward "/policies" to Ember for a moment
location = /policies {
proxy_pass http://localhost:9000;
}

location ~ ^/api/v./crates/new$ {
proxy_pass http://app_server;

Expand Down
56 changes: 56 additions & 0 deletions fastboot.js
@@ -0,0 +1,56 @@
/* eslint-disable no-console */

'use strict';

const fs = require('fs');
const FastBootAppServer = require('fastboot-app-server');

// because fastboot-app-server uses cluster, but it might change in future
const cluster = require('cluster');

class LoggerWithoutTimestamp {
constructor() {
this.prefix = cluster.isMaster ? 'master' : 'worker';
}
writeLine() {
this._write('info', Array.prototype.slice.apply(arguments));
}

writeError() {
this._write('error', Array.prototype.slice.apply(arguments));
}

_write(level, args) {
args[0] = `[${level}][${this.prefix}] ${args[0]}`;
console.log.apply(console, args);
}
}

function writeAppInitializedWhenReady(logger) {
let timeout;

timeout = setInterval(function() {
logger.writeLine('waiting backend');
if (fs.existsSync('/tmp/backend-initialized')) {
logger.writeLine('backend is up. let heroku know the app is ready');
fs.writeFileSync('/tmp/app-initialized', 'hello');
clearInterval(timeout);
} else {
logger.writeLine('backend is still not up');
}
}, 1000);
}

var logger = new LoggerWithoutTimestamp();

let server = new FastBootAppServer({
distPath: 'dist',
port: 9000,
ui: logger,
});

if (!cluster.isWorker) {
writeAppInitializedWhenReady(logger);
}

server.start();
8 changes: 8 additions & 0 deletions fastboot/initializers/ajax.js
@@ -0,0 +1,8 @@
export default {
name: 'ajax-service',
initialize() {
// This is to override Fastboot's initializer which prevents ember-fetch from working
// https://github.com/ember-fastboot/ember-cli-fastboot/blob/master/fastboot/initializers/ajax.js
// https://github.com/ember-cli/ember-fetch#ajax-service
},
};
2 changes: 2 additions & 0 deletions foreman-procfile
@@ -0,0 +1,2 @@
ember: node fastboot.js
api: ./target/release/server

0 comments on commit 111b7eb

Please sign in to comment.