Skip to content

Commit 0ec87c8

Browse files
authored
Merge pull request #955 from ember-learn/kg-fix-fastboot
2 parents 5d3b44f + 6044001 commit 0ec87c8

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

app/adapters/application.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { inject as service } from '@ember/service';
22
import JSONAPIAdapter from '@ember-data/adapter/json-api';
33
import { pluralize } from 'ember-inflector';
44
import { isBlank } from '@ember/utils';
5+
import config from 'ember-api-docs/config/environment';
56

67
export default class Application extends JSONAPIAdapter {
78
currentProject = '';
@@ -39,7 +40,6 @@ export default class Application extends JSONAPIAdapter {
3940

4041
async findRecord(store, { modelName }, id) {
4142
let url;
42-
// let host = this.host;
4343
let projectName = this.currentProject;
4444

4545
if (['namespace', 'class', 'module'].indexOf(modelName) > -1) {
@@ -77,10 +77,23 @@ export default class Application extends JSONAPIAdapter {
7777
throw new Error('Unexpected model lookup');
7878
}
7979

80-
url = `/${url}.json`;
80+
const base = this.fastboot.isFastBoot
81+
? config.APP.domain
82+
: window.location.origin;
8183

82-
let response = await fetch(url);
83-
let json = await response.json();
84-
return json;
84+
url = `${base}/${url}.json`;
85+
try {
86+
let response = await fetch(url);
87+
if (!response.ok) {
88+
throw new Error(
89+
`Network response was not ok: ${response.status} ${response.statusText}`
90+
);
91+
}
92+
let json = await response.json();
93+
return json;
94+
} catch (error) {
95+
console.error(`Failed to fetch or parse JSON from ${url}:`, error);
96+
throw new Error(`Failed to load data for ${url}: ${error.message}`);
97+
}
8598
}
8699
}

config/fastboot.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ module.exports = function () {
33
buildSandboxGlobals(defaultGlobals) {
44
return Object.assign({}, defaultGlobals, {
55
atob: atob,
6+
AbortController,
7+
fetch: fetch,
8+
ReadableStream:
9+
typeof ReadableStream !== 'undefined'
10+
? ReadableStream
11+
: require('node:stream/web').ReadableStream,
12+
WritableStream:
13+
typeof WritableStream !== 'undefined'
14+
? WritableStream
15+
: require('node:stream/web').WritableStream,
16+
TransformStream:
17+
typeof TransformStream !== 'undefined'
18+
? TransformStream
19+
: require('node:stream/web').TransformStream,
20+
Headers: typeof Headers !== 'undefined' ? Headers : undefined,
621
});
722
},
823
};

0 commit comments

Comments
 (0)