Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ which helps getting the HTML to clients faster.

[ember-cli-fastboot]: https://github.com/ember-fastboot/ember-cli-fastboot

## VisitOptions

For sending over additional metadata so that it could be leveraged by the consuming app/addon, you can pass the `visitOptions` option that contains any extra information that might be necessary.

Example usecase: If an addon relies on some metadata that is set by the consuming app, then in that case the addon will not have the access to the metadata value. In such cases, developing against dummy app becomes difficult. Hence, passing in the `visitOptions` will enable smoother local addon development.

```js
app.get('/*', fastbootMiddleware({
distPath: '/path/to/dist',
visitOptions: {
metadata: {
foo: 'bar'
}
}
}));
```

## Tests

`npm test`
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function fastbootExpressMiddleware(distPath, options) {
let path = req.url;

try {
let result = await fastboot.visit(path, { request: req, response: res });
let visitOptions = Object.assign({}, opts.visitOptions, { request: req, response: res });
let result = await fastboot.visit(path, visitOptions);
let body = opts.chunkedResponse ? await result.chunks() : await result.html();

if (result.error) {
Expand Down
Empty file.
83 changes: 83 additions & 0 deletions test/fixtures/app-with-metadata/assets/fastboot-app-fastboot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
define('~fastboot/app-factory', ['fastboot-app/app', 'fastboot-app/config/environment'], function(App, config) {
App = App['default'];
config = config['default'];

return {
'default': function() {
return App.create(config.APP);
}
};
});

define("fastboot-app/initializers/ajax", ["exports"], function (_exports) {
"use strict";

Object.defineProperty(_exports, "__esModule", {
value: true
});
_exports.default = void 0;
const {
get
} = Ember;

var nodeAjax = function (options) {
let httpRegex = /^https?:\/\//;
let protocolRelativeRegex = /^\/\//;
let protocol = get(this, 'fastboot.request.protocol');

if (protocolRelativeRegex.test(options.url)) {
options.url = protocol + options.url;
} else if (!httpRegex.test(options.url)) {
try {
options.url = protocol + '//' + get(this, 'fastboot.request.host') + options.url;
} catch (fbError) {
throw new Error('You are using Ember Data with no host defined in your adapter. This will attempt to use the host of the FastBoot request, which is not configured for the current host of this request. Please set the hostWhitelist property for in your environment.js. FastBoot Error: ' + fbError.message);
}
}

if (najax) {
najax(options);
} else {
throw new Error('najax does not seem to be defined in your app. Did you override it via `addOrOverrideSandboxGlobals` in the fastboot server?');
}
};

var _default = {
name: 'ajax-service',
initialize: function (application) {
application.register('ajax:node', nodeAjax, {
instantiate: false
});
application.inject('adapter', '_ajaxRequest', 'ajax:node');
application.inject('adapter', 'fastboot', 'service:fastboot');
}
};
_exports.default = _default;
});
define("fastboot-app/initializers/error-handler", ["exports"], function (_exports) {
"use strict";

Object.defineProperty(_exports, "__esModule", {
value: true
});
_exports.default = void 0;

/**
* Initializer to attach an `onError` hook to your app running in fastboot. It catches any run loop
* exceptions and other errors and prevents the node process from crashing.
*
*/
var _default = {
name: 'error-handler',
initialize: function () {
if (!Ember.onerror) {
// if no onerror handler is defined, define one for fastboot environments
Ember.onerror = function (err) {
const errorMessage = `There was an error running your app in fastboot. More info about the error: \n ${err.stack || err}`;
console.error(errorMessage);
};
}
}
};
_exports.default = _default;
});//# sourceMappingURL=fastboot-app-fastboot.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Loading