46 lines
909 B
JavaScript
46 lines
909 B
JavaScript
import {ApiRequestHandler, registerApiRequestHandler} from './api';
|
|
|
|
export const data = {
|
|
'/api/config.json': {
|
|
workspace: '/workspace/test',
|
|
},
|
|
'/api/workspace/test': {
|
|
name: "Some workspace",
|
|
tree: [],
|
|
open: [
|
|
{
|
|
uri: ""
|
|
}
|
|
],
|
|
settings: {},
|
|
},
|
|
};
|
|
|
|
function lookupData(url) {
|
|
const {pathname} = new URL(url);
|
|
return data[pathname];
|
|
}
|
|
|
|
class FixtureApiRequestHandler extends ApiRequestHandler {
|
|
|
|
doesFetchEndpoint(input) {
|
|
const url = ApiRequestHandler.normalizeRequestUrl(input);
|
|
return !!lookupData(url);
|
|
}
|
|
|
|
fetch(input, init) {
|
|
const url = ApiRequestHandler.normalizeRequestUrl(input);
|
|
const data = lookupData(url);
|
|
return new Response(
|
|
JSON.stringify(data), {
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
registerApiRequestHandler(new FixtureApiRequestHandler());
|