feat: Move runtime config into dedicated component, Closes #67

* Move runtime config into dedicated component, Closes #67

* Migrate FileResourceStore to RuntimeConfig
This commit is contained in:
Ruben Taelman
2020-08-26 10:25:47 +02:00
committed by GitHub
parent 4f8ebff7f7
commit 5126356c94
14 changed files with 194 additions and 84 deletions

View File

@@ -11,6 +11,7 @@ import {
QuadToTurtleConverter,
Representation,
RepresentationConvertingStore,
RuntimeConfig,
Setup,
SimpleAclAuthorizer,
SimpleBodyParser,
@@ -36,15 +37,13 @@ import {
const { argv } = yargs
.usage('node ./bin/server.js [args]')
.options({
port: { type: 'number', alias: 'p', default: 3000 },
port: { type: 'number', alias: 'p' },
})
.help();
const { port } = argv;
const base = `http://localhost:${port}/`;
// This is instead of the dependency injection that still needs to be added
const runtimeConfig = new RuntimeConfig();
const bodyParser = new CompositeAsyncHandler<HttpRequest, Representation | undefined>([
new SimpleSparqlUpdateBodyParser(),
new SimpleBodyParser(),
@@ -62,7 +61,7 @@ const permissionsExtractor = new CompositeAsyncHandler([
]);
// Will have to see how to best handle this
const store = new SimpleResourceStore(base);
const store = new SimpleResourceStore(runtimeConfig);
const converter = new CompositeAsyncHandler([
new TurtleToQuadConverter(),
new QuadToTurtleConverter(),
@@ -73,7 +72,7 @@ const patcher = new SimpleSparqlUpdatePatchHandler(convertingStore, locker);
const patchingStore = new PatchingStore(convertingStore, patcher);
const aclManager = new SimpleExtensionAclManager();
const containerManager = new UrlContainerManager(base);
const containerManager = new UrlContainerManager(runtimeConfig);
const authorizer = new SimpleAclAuthorizer(aclManager, containerManager, patchingStore);
const operationHandler = new CompositeAsyncHandler([
@@ -97,9 +96,11 @@ const httpHandler = new AuthenticatedLdpHandler({
const httpServer = new ExpressHttpServer(httpHandler);
const setup = new Setup(httpServer, store, aclManager);
setup.setup(port, base).then((): void => {
process.stdout.write(`Running at ${base}\n`);
const setup = new Setup(httpServer, store, aclManager, runtimeConfig);
runtimeConfig.reset({ port: argv.port });
setup.setup().then((): void => {
process.stdout.write(`Running at ${runtimeConfig.base}\n`);
}).catch((error): void => {
process.stderr.write(`${error}\n`);
process.exit(1);