refactor: include latest changes from core#145

This commit is contained in:
Rainer Killinger
2022-01-21 15:30:23 +01:00
parent 482dec345c
commit 9d8fe643a5
13 changed files with 316 additions and 260 deletions

View File

@@ -30,6 +30,7 @@ export const indexRouter = createRoute<unknown, SCIndexResponse>(
async (): Promise<SCIndexResponse> => {
return {
app: configFile.app,
auth: configFile.auth,
backend: configFile.backend,
};
},

View File

@@ -23,7 +23,7 @@ import {
} from '@openstapps/core';
import {Logger} from '@openstapps/logger';
import {deepStrictEqual} from 'assert';
import {isTestEnvironment, plugins} from '../common';
import {configFile, isTestEnvironment, plugins} from '../common';
import {createRoute} from './route';
/**
@@ -76,6 +76,11 @@ function addPlugin(plugin: SCPluginMetaData): SCPluginRegisterResponse {
}
// it's a new plugin so it can be added to the map of plugins
plugins.set(plugin.route, plugin);
// add plugin info to app config
if (typeof configFile.app.features.plugins === 'undefined') {
configFile.app.features.plugins = {};
}
configFile.app.features.plugins[plugin.name] = {urlPath : plugin.route};
Logger.log(`Registered plugin (name: ${plugin.name}, address: ${plugin.address}) on the route "${plugin.route}".`);
return {success: true};
@@ -92,6 +97,10 @@ function removePlugin(route: string): SCPluginRegisterResponse {
isTestEnvironment,
);
}
if (plugins.has(route)) {
const plugin = plugins.get(route)!;
delete configFile.app.features.plugins?.[plugin.name];
}
// remove the plugin information using its route as a key
plugins.delete(route);
Logger.log(`Removed plugin that used the route "${route}".`);

View File

@@ -47,7 +47,7 @@ export function createRoute<REQUESTTYPE, RETURNTYPE>(
// create route
// the given type has no index signature so we have to cast to get the IRouteHandler when a HTTP method is given
const route = router.route(routeClass.urlFragment);
const route = router.route(routeClass.urlPath);
const verb = routeClass.method.toLowerCase();