Skip to content

Commit 6289968

Browse files
author
Robert Jackson
authored
Merge pull request #66 from suchitadoshi1987/suchita/metadata
2 parents f03c96f + 8ac7b9a commit 6289968

23 files changed

+111627
-1
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,23 @@ which helps getting the HTML to clients faster.
107107

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

110+
## VisitOptions
111+
112+
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.
113+
114+
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.
115+
116+
```js
117+
app.get('/*', fastbootMiddleware({
118+
distPath: '/path/to/dist',
119+
visitOptions: {
120+
metadata: {
121+
foo: 'bar'
122+
}
123+
}
124+
}));
125+
```
126+
110127
## Tests
111128

112129
`npm test`

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ function fastbootExpressMiddleware(distPath, options) {
2929
let path = req.url;
3030

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

3536
if (result.error) {

test/fixtures/app-with-metadata/assets/auto-import-fastboot.js

Whitespace-only changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
define('~fastboot/app-factory', ['fastboot-app/app', 'fastboot-app/config/environment'], function(App, config) {
2+
App = App['default'];
3+
config = config['default'];
4+
5+
return {
6+
'default': function() {
7+
return App.create(config.APP);
8+
}
9+
};
10+
});
11+
12+
define("fastboot-app/initializers/ajax", ["exports"], function (_exports) {
13+
"use strict";
14+
15+
Object.defineProperty(_exports, "__esModule", {
16+
value: true
17+
});
18+
_exports.default = void 0;
19+
const {
20+
get
21+
} = Ember;
22+
23+
var nodeAjax = function (options) {
24+
let httpRegex = /^https?:\/\//;
25+
let protocolRelativeRegex = /^\/\//;
26+
let protocol = get(this, 'fastboot.request.protocol');
27+
28+
if (protocolRelativeRegex.test(options.url)) {
29+
options.url = protocol + options.url;
30+
} else if (!httpRegex.test(options.url)) {
31+
try {
32+
options.url = protocol + '//' + get(this, 'fastboot.request.host') + options.url;
33+
} catch (fbError) {
34+
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);
35+
}
36+
}
37+
38+
if (najax) {
39+
najax(options);
40+
} else {
41+
throw new Error('najax does not seem to be defined in your app. Did you override it via `addOrOverrideSandboxGlobals` in the fastboot server?');
42+
}
43+
};
44+
45+
var _default = {
46+
name: 'ajax-service',
47+
initialize: function (application) {
48+
application.register('ajax:node', nodeAjax, {
49+
instantiate: false
50+
});
51+
application.inject('adapter', '_ajaxRequest', 'ajax:node');
52+
application.inject('adapter', 'fastboot', 'service:fastboot');
53+
}
54+
};
55+
_exports.default = _default;
56+
});
57+
define("fastboot-app/initializers/error-handler", ["exports"], function (_exports) {
58+
"use strict";
59+
60+
Object.defineProperty(_exports, "__esModule", {
61+
value: true
62+
});
63+
_exports.default = void 0;
64+
65+
/**
66+
* Initializer to attach an `onError` hook to your app running in fastboot. It catches any run loop
67+
* exceptions and other errors and prevents the node process from crashing.
68+
*
69+
*/
70+
var _default = {
71+
name: 'error-handler',
72+
initialize: function () {
73+
if (!Ember.onerror) {
74+
// if no onerror handler is defined, define one for fastboot environments
75+
Ember.onerror = function (err) {
76+
const errorMessage = `There was an error running your app in fastboot. More info about the error: \n ${err.stack || err}`;
77+
console.error(errorMessage);
78+
};
79+
}
80+
}
81+
};
82+
_exports.default = _default;
83+
});//# sourceMappingURL=fastboot-app-fastboot.map

test/fixtures/app-with-metadata/assets/fastboot-app-fastboot.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/app-with-metadata/assets/fastboot-app.css

Whitespace-only changes.

0 commit comments

Comments
 (0)