Skip to content

Commit

Permalink
Remove unused "fastboot" code
Browse files Browse the repository at this point in the history
Ember.js "fastboot" allows us to server-render the app and send HTML over the wire. While this sounds good in theory, using it in practice has shown that it requires significantly more server-side resources and causes a lot of additional complexity. This part of the codebase hasn't been used for years and if we would move to server-side rendering then it probably would be combined with moving to a different framework/architecture. Thus it is time for the fastboot code and complexity to be removed from the codebase.
  • Loading branch information
Turbo87 committed Oct 17, 2023
1 parent 1607579 commit 388b77d
Show file tree
Hide file tree
Showing 21 changed files with 94 additions and 678 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ module.exports = {
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'fastboot.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
Expand Down
11 changes: 0 additions & 11 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
import RESTAdapter from '@ember-data/adapter/rest';
import { inject as service } from '@ember/service';

export default class ApplicationAdapter extends RESTAdapter {
@service fastboot;

namespace = 'api/v1';

get headers() {
if (this.fastboot.isFastBoot) {
return { 'User-Agent': this.fastboot.request.headers.get('User-Agent') };
}

return {};
}

handleResponse(status, headers, payload, requestData) {
if (typeof payload === 'string') {
try {
Expand Down
8 changes: 3 additions & 5 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import Resolver from 'ember-resolver';
import config from './config/environment';
import * as Sentry from './sentry';

if (typeof FastBoot === 'undefined') {
// eslint-disable-next-line unicorn/prefer-add-event-listener
window.onerror = undefined;
Sentry.init();
}
// eslint-disable-next-line unicorn/prefer-add-event-listener
window.onerror = undefined;
Sentry.init();

export default class App extends Application {
modulePrefix = config.modulePrefix;
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { inject as service } from '@ember/service';
import { dropTask } from 'ember-concurrency';
import { reads } from 'macro-decorators';

import ajax from '../utils/ajax';

export default class IndexController extends Controller {
@service fetcher;
@service store;

@reads('dataTask.lastSuccessful.value') model;
Expand All @@ -22,7 +23,7 @@ export default class IndexController extends Controller {
}

dataTask = dropTask(async () => {
let data = await this.fetcher.ajax('/api/v1/summary');
let data = await ajax('/api/v1/summary');

addCrates(this.store, data.new_crates);
addCrates(this.store, data.most_downloaded);
Expand Down
4 changes: 0 additions & 4 deletions app/initializers/hashchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ function hashchange() {
}

export function initialize() {
if (typeof window === 'undefined' || window.addEventListener === undefined) {
// Don't run this initializer under FastBoot
return;
}
window.addEventListener('hashchange', hashchange);

// If clicking on a link to the same fragment as currently in the address bar,
Expand Down
8 changes: 1 addition & 7 deletions app/routes/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';

export default class IndexRoute extends Route {
@service fastboot;

setupController(controller) {
if (!controller.hasData) {
let promise = controller.fetchData();
if (this.fastboot.isFastBoot) {
this.fastboot.deferRendering(promise);
}
controller.fetchData();
}
}
}
2 changes: 0 additions & 2 deletions app/services/design.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import * as localStorage from '../utils/local-storage';
const KNOWN_THEMES = new Set(['classic', 'new-design']);

export default class DesignService extends Service {
@service fastboot;

@tracked _theme = localStorage.getItem('theme');
@tracked showToggleButton = config.environment === 'development' || config.environment === 'test';

Expand Down
31 changes: 0 additions & 31 deletions app/services/fetcher.js

This file was deleted.

12 changes: 2 additions & 10 deletions app/services/redirector.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import Service, { inject as service } from '@ember/service';
import Service from '@ember/service';

import window from 'ember-window-mock';

export default class RedirectorService extends Service {
@service fastboot;

redirectTo(url) {
if (this.fastboot.isFastBoot) {
let headers = this.fastboot.response.headers;
headers.set('location', url);
this.set('fastboot.response.statusCode', 301);
} else {
window.location = url;
}
window.location = url;
}
}
4 changes: 0 additions & 4 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ module.exports = function (environment) {
// when it is created
},

fastboot: {
hostWhitelist: ['crates.io', /^localhost:\d+$/, /\.herokuapp\.com$/],
},

'ember-cli-notifications': {
autoClear: true,
clearDuration: 10_000,
Expand Down
31 changes: 3 additions & 28 deletions config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -232,33 +232,8 @@ http {
rewrite ^ https://$host$request_uri? permanent;
}

<% if ENV['USE_FASTBOOT'] == "staging-experimental" %>
# Experimentally send all non-backend requests to FastBoot

location /api/ {
proxy_pass http://app_server;
}

# FastBoot
location / {
proxy_pass http://localhost:9000;
}
<% elsif ENV['USE_FASTBOOT'] && !ENV['USE_FASTBOOT'].empty? %>
# Fastboot is enabled only for allowed paths

location = /policies {
proxy_pass http://localhost:9000;
}

location / {
proxy_pass http://app_server;
}
<% else %>
# FastBoot is disabled, backend sends the static Ember index HTML for non-backend paths

location / {
proxy_pass http://app_server;
}
<% end %>
location / {
proxy_pass http://app_server;
}
}
}
70 changes: 0 additions & 70 deletions fastboot.js

This file was deleted.

10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
"lint:hbs": "ember-template-lint app",
"lint:js": "eslint . --cache",
"prettier": "prettier --write package.json '**/*.js'",
"start": "./script/ember.sh serve",
"start:live": "PROXY_BACKEND=https://crates.io ./script/ember.sh serve",
"start:local": "PROXY_BACKEND=http://127.0.0.1:8888 ./script/ember.sh serve",
"start:staging": "PROXY_BACKEND=https://staging-crates-io.herokuapp.com ./script/ember.sh serve",
"start": "ember serve",
"start:live": "PROXY_BACKEND=https://crates.io ember serve",
"start:local": "PROXY_BACKEND=http://127.0.0.1:8888 ember serve",
"start:staging": "PROXY_BACKEND=https://staging-crates-io.herokuapp.com ember serve",
"test": "ember exam --split=2 --parallel",
"test-coverage": "COVERAGE=true npm run test && ember coverage-merge && rm -rf coverage_* coverage/coverage-summary.json && nyc report"
},
Expand All @@ -43,7 +43,6 @@
"chart.js": "4.4.0",
"copy-text-to-clipboard": "3.2.0",
"date-fns": "2.30.0",
"fastboot-app-server": "4.1.1",
"highlight.js": "11.9.0",
"macro-decorators": "0.1.2",
"mermaid": "10.5.0",
Expand Down Expand Up @@ -82,7 +81,6 @@
"ember-cli-dependency-checker": "3.3.2",
"ember-cli-dependency-lint": "2.0.1",
"ember-cli-deprecation-workflow": "2.1.0",
"ember-cli-fastboot": "4.1.1",
"ember-cli-head": "2.0.0",
"ember-cli-htmlbars": "6.3.0",
"ember-cli-inject-live-reload": "2.1.0",
Expand Down
Loading

0 comments on commit 388b77d

Please sign in to comment.