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
23 changes: 18 additions & 5 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { inject as service } from '@ember/service';
import JSONAPIAdapter from '@ember-data/adapter/json-api';
import { pluralize } from 'ember-inflector';
import { isBlank } from '@ember/utils';
import config from 'ember-api-docs/config/environment';

export default class Application extends JSONAPIAdapter {
currentProject = '';
Expand Down Expand Up @@ -39,7 +40,6 @@ export default class Application extends JSONAPIAdapter {

async findRecord(store, { modelName }, id) {
let url;
// let host = this.host;
let projectName = this.currentProject;

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

url = `/${url}.json`;
const base = this.fastboot.isFastBoot
? config.APP.domain
: window.location.origin;

let response = await fetch(url);
let json = await response.json();
return json;
url = `${base}/${url}.json`;
try {
let response = await fetch(url);
if (!response.ok) {
throw new Error(
`Network response was not ok: ${response.status} ${response.statusText}`
);
}
let json = await response.json();
return json;
} catch (error) {
console.error(`Failed to fetch or parse JSON from ${url}:`, error);
throw new Error(`Failed to load data for ${url}: ${error.message}`);
}
}
}
15 changes: 15 additions & 0 deletions config/fastboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ module.exports = function () {
buildSandboxGlobals(defaultGlobals) {
return Object.assign({}, defaultGlobals, {
atob: atob,
AbortController,
fetch: fetch,
ReadableStream:
typeof ReadableStream !== 'undefined'
? ReadableStream
: require('node:stream/web').ReadableStream,
WritableStream:
typeof WritableStream !== 'undefined'
? WritableStream
: require('node:stream/web').WritableStream,
TransformStream:
typeof TransformStream !== 'undefined'
? TransformStream
: require('node:stream/web').TransformStream,
Headers: typeof Headers !== 'undefined' ? Headers : undefined,
});
},
};
Expand Down