Let the Backend manage creating databases
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
import Router from 'express-promise-router';
|
||||
import {
|
||||
ensureDatabaseExists,
|
||||
createDatabaseClient,
|
||||
createServiceBuilder,
|
||||
loadBackendConfig,
|
||||
@@ -49,9 +50,9 @@ import { PluginEnvironment } from './types';
|
||||
function makeCreateEnv(loadedConfigs: AppConfig[]) {
|
||||
const config = ConfigReader.fromConfigs(loadedConfigs);
|
||||
|
||||
return async (plugin: string): Promise<PluginEnvironment> => {
|
||||
return (plugin: string): PluginEnvironment => {
|
||||
const logger = getRootLogger().child({ type: 'plugin', plugin });
|
||||
const database = await createDatabaseClient(
|
||||
const database = createDatabaseClient(
|
||||
config.getConfig('backend.database'),
|
||||
{
|
||||
connection: {
|
||||
@@ -68,41 +69,41 @@ async function main() {
|
||||
const configs = await loadBackendConfig();
|
||||
const configReader = ConfigReader.fromConfigs(configs);
|
||||
const createEnv = makeCreateEnv(configs);
|
||||
const healthcheckEnv = useHotMemoize(module, async () =>
|
||||
createEnv('healthcheck'),
|
||||
await ensureDatabaseExists(
|
||||
configReader.getConfig('backend.database'),
|
||||
'backstage_plugin_catalog',
|
||||
'backstage_plugin_auth',
|
||||
);
|
||||
const catalogEnv = useHotMemoize(module, async () => createEnv('catalog'));
|
||||
const scaffolderEnv = useHotMemoize(module, async () =>
|
||||
createEnv('scaffolder'),
|
||||
);
|
||||
const authEnv = useHotMemoize(module, async () => createEnv('auth'));
|
||||
const proxyEnv = useHotMemoize(module, async () => createEnv('proxy'));
|
||||
const rollbarEnv = useHotMemoize(module, async () => createEnv('rollbar'));
|
||||
const sentryEnv = useHotMemoize(module, async () => createEnv('sentry'));
|
||||
const techdocsEnv = useHotMemoize(module, async () => createEnv('techdocs'));
|
||||
const kubernetesEnv = useHotMemoize(module, async () =>
|
||||
createEnv('kubernetes'),
|
||||
);
|
||||
const graphqlEnv = useHotMemoize(module, async () => createEnv('graphql'));
|
||||
const appEnv = useHotMemoize(module, async () => createEnv('app'));
|
||||
|
||||
const healthcheckEnv = useHotMemoize(module, () => createEnv('healthcheck'));
|
||||
const catalogEnv = useHotMemoize(module, () => createEnv('catalog'));
|
||||
const scaffolderEnv = useHotMemoize(module, () => createEnv('scaffolder'));
|
||||
const authEnv = useHotMemoize(module, () => createEnv('auth'));
|
||||
const proxyEnv = useHotMemoize(module, () => createEnv('proxy'));
|
||||
const rollbarEnv = useHotMemoize(module, () => createEnv('rollbar'));
|
||||
const sentryEnv = useHotMemoize(module, () => createEnv('sentry'));
|
||||
const techdocsEnv = useHotMemoize(module, () => createEnv('techdocs'));
|
||||
const kubernetesEnv = useHotMemoize(module, () => createEnv('kubernetes'));
|
||||
const graphqlEnv = useHotMemoize(module, () => createEnv('graphql'));
|
||||
const appEnv = useHotMemoize(module, () => createEnv('app'));
|
||||
|
||||
const apiRouter = Router();
|
||||
apiRouter.use('/catalog', await catalog(await catalogEnv));
|
||||
apiRouter.use('/rollbar', await rollbar(await rollbarEnv));
|
||||
apiRouter.use('/scaffolder', await scaffolder(await scaffolderEnv));
|
||||
apiRouter.use('/sentry', await sentry(await sentryEnv));
|
||||
apiRouter.use('/auth', await auth(await authEnv));
|
||||
apiRouter.use('/techdocs', await techdocs(await techdocsEnv));
|
||||
apiRouter.use('/kubernetes', await kubernetes(await kubernetesEnv));
|
||||
apiRouter.use('/proxy', await proxy(await proxyEnv));
|
||||
apiRouter.use('/graphql', await graphql(await graphqlEnv));
|
||||
apiRouter.use('/catalog', await catalog(catalogEnv));
|
||||
apiRouter.use('/rollbar', await rollbar(rollbarEnv));
|
||||
apiRouter.use('/scaffolder', await scaffolder(scaffolderEnv));
|
||||
apiRouter.use('/sentry', await sentry(sentryEnv));
|
||||
apiRouter.use('/auth', await auth(authEnv));
|
||||
apiRouter.use('/techdocs', await techdocs(techdocsEnv));
|
||||
apiRouter.use('/kubernetes', await kubernetes(kubernetesEnv));
|
||||
apiRouter.use('/proxy', await proxy(proxyEnv));
|
||||
apiRouter.use('/graphql', await graphql(graphqlEnv));
|
||||
apiRouter.use(notFoundHandler());
|
||||
|
||||
const service = createServiceBuilder(module)
|
||||
.loadConfig(configReader)
|
||||
.addRouter('', await healthcheck(await healthcheckEnv))
|
||||
.addRouter('', await healthcheck(healthcheckEnv))
|
||||
.addRouter('/api', apiRouter)
|
||||
.addRouter('', await app(await appEnv));
|
||||
.addRouter('', await app(appEnv));
|
||||
|
||||
await service.start().catch(err => {
|
||||
console.log(err);
|
||||
|
||||
Reference in New Issue
Block a user