chore: wiring up the catalog 📕
Co-authored-by: Fredrik Adelöw <freben@gmail.com> Co-authored-by: Johan Haals <johan.haals@gmail.com> Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com> Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
"@backstage/backend-common": "^0.14.0",
|
||||
"@backstage/backend-tasks": "^0.3.2",
|
||||
"@backstage/plugin-permission-node": "^0.6.2",
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"winston": "^3.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {
|
||||
createServiceFactory,
|
||||
httpRouterServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import Router from 'express-promise-router';
|
||||
import express, { Handler } from 'express';
|
||||
|
||||
export const httpRouterFactory = createServiceFactory({
|
||||
service: httpRouterServiceRef,
|
||||
deps: {},
|
||||
factory: async () => {
|
||||
const app = express();
|
||||
const rootRouter = Router();
|
||||
|
||||
app.use(rootRouter);
|
||||
app.listen(8123);
|
||||
|
||||
return async (pluginId?: string) => {
|
||||
if (!pluginId) {
|
||||
return rootRouter;
|
||||
}
|
||||
return {
|
||||
use(handler: Handler) {
|
||||
rootRouter.use(`/api/${pluginId}`, handler);
|
||||
},
|
||||
};
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -23,6 +23,7 @@ import { permissionsFactory } from './permissionsService';
|
||||
import { schedulerFactory } from './schedulerService';
|
||||
import { tokenManagerFactory } from './tokenManagerService';
|
||||
import { urlReaderFactory } from './urlReaderService';
|
||||
import { httpRouterFactory } from './httpRouterService';
|
||||
|
||||
export const defaultServiceFactories = [
|
||||
cacheFactory,
|
||||
@@ -34,4 +35,5 @@ export const defaultServiceFactories = [
|
||||
schedulerFactory,
|
||||
tokenManagerFactory,
|
||||
urlReaderFactory,
|
||||
httpRouterFactory,
|
||||
];
|
||||
|
||||
@@ -37,10 +37,12 @@
|
||||
"@backstage/config": "^1.0.1",
|
||||
"@backstage/backend-common": "^0.14.0",
|
||||
"@backstage/plugin-permission-common": "^0.6.2",
|
||||
"@backstage/backend-tasks": "^0.3.2"
|
||||
"@backstage/backend-tasks": "^0.3.2",
|
||||
"express": "^4.17.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.17.2-next.0"
|
||||
"@backstage/cli": "^0.17.2-next.0",
|
||||
"@types/express": "^4.17.6"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
|
||||
@@ -15,11 +15,30 @@
|
||||
*/
|
||||
|
||||
import { createServiceRef } from '../system/types';
|
||||
import { Handler } from 'express';
|
||||
|
||||
export interface HttpRouterApi {
|
||||
get(path: string): void;
|
||||
// const apiRouter = Router();
|
||||
// apiRouter.use('/catalog', await catalog(catalogEnv));
|
||||
// const service = createServiceBuilder(module)
|
||||
// .loadConfig(config)
|
||||
// .addRouter('', await healthcheck(healthcheckEnv))
|
||||
// .addRouter('', metricsHandler())
|
||||
// .addRouter('/api', apiRouter)
|
||||
// .addRouter('', await app(appEnv));
|
||||
|
||||
// interface BackstageRequest extends Request {
|
||||
// identity?: BackstageIdentity;
|
||||
// context?: Context;
|
||||
// }
|
||||
|
||||
// interface RequestIdentityService {
|
||||
// getRequestIdentity(req: Request): BackstageIdentity | undefined;
|
||||
// }
|
||||
|
||||
export interface HttpRouterService {
|
||||
use(handler: Handler): void;
|
||||
}
|
||||
|
||||
export const httpRouterServiceRef = createServiceRef<HttpRouterApi>({
|
||||
export const httpRouterServiceRef = createServiceRef<HttpRouterService>({
|
||||
id: 'core.httpRouter',
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
export { configServiceRef } from './configServiceRef';
|
||||
export { httpRouterServiceRef } from './httpRouterServiceRef';
|
||||
export type { HttpRouterApi } from './httpRouterServiceRef';
|
||||
export type { HttpRouterService } from './httpRouterServiceRef';
|
||||
export { loggerServiceRef } from './loggerServiceRef';
|
||||
export type { Logger } from './loggerServiceRef';
|
||||
export { urlReaderServiceRef } from './urlReaderServiceRef';
|
||||
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
loggerServiceRef,
|
||||
permissionsServiceRef,
|
||||
urlReaderServiceRef,
|
||||
httpRouterServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
CatalogBuilder,
|
||||
@@ -72,8 +73,16 @@ export const catalogPlugin = createBackendPlugin({
|
||||
reader: urlReaderServiceRef,
|
||||
permissions: permissionsServiceRef,
|
||||
database: databaseServiceRef,
|
||||
httpRouter: httpRouterServiceRef,
|
||||
},
|
||||
async init({ logger, config, reader, database, permissions }) {
|
||||
async init({
|
||||
logger,
|
||||
config,
|
||||
reader,
|
||||
database,
|
||||
permissions,
|
||||
httpRouter,
|
||||
}) {
|
||||
const winstonLogger = loggerToWinstonLogger(logger);
|
||||
const builder = await CatalogBuilder.create({
|
||||
config,
|
||||
@@ -82,9 +91,12 @@ export const catalogPlugin = createBackendPlugin({
|
||||
database,
|
||||
logger: winstonLogger,
|
||||
});
|
||||
builder.addProcessor(processingExtensions.processors);
|
||||
const { processingEngine } = await builder.build();
|
||||
builder.addProcessor(...processingExtensions.processors);
|
||||
const { processingEngine, router } = await builder.build();
|
||||
|
||||
await processingEngine.start();
|
||||
|
||||
httpRouter.use(router);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user