mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
chore: Remove assumption that DataAccessors have a root container by default
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import type { Server } from 'http';
|
||||
import { join } from 'path';
|
||||
import * as Path from 'path';
|
||||
import { Loader } from 'componentsjs';
|
||||
import fetch from 'cross-fetch';
|
||||
import type {
|
||||
BodyParser,
|
||||
DataAccessor,
|
||||
@@ -24,6 +26,7 @@ import {
|
||||
ErrorResponseWriter,
|
||||
GetOperationHandler,
|
||||
HeadOperationHandler,
|
||||
HttpError,
|
||||
InMemoryDataAccessor,
|
||||
LinkRelMetadataWriter,
|
||||
LinkTypeParser,
|
||||
@@ -192,3 +195,21 @@ export const instantiateFromConfig = async(componentUrl: string, configFile: str
|
||||
const configPath = Path.join(__dirname, configFile);
|
||||
return loader.instantiateFromUrl(componentUrl, configPath, undefined, { variables });
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes the root container of the server.
|
||||
* Useful for when the RootContainerInitializer was not instantiated.
|
||||
*/
|
||||
export const initServerStore = async(server: Server, baseUrl: string, headers: HeadersInit = {}): Promise<void> => {
|
||||
const res = await fetch(baseUrl, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
...headers,
|
||||
'content-type': 'text/turtle',
|
||||
},
|
||||
body: '',
|
||||
});
|
||||
if (res.status >= 400) {
|
||||
throw new HttpError(res.status, 'Error', res.statusText);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user