Skip to content

A backstage backend plugin support gRPC playground for API entities and normal requests

License

Notifications You must be signed in to change notification settings

zalopay-oss/backstage-grpc-playground-backend

Repository files navigation

backstage-grpc-playground-backend

GitHub Project Level GitHub issues GitHub contributors GitHub code size in bytes

Overview

This repo contains backend code of the backstage-grpc-playground

Install

Install backstage-grpc-playground-backend for packages/backend

E.g: In your backstage project root

  yarn --cwd packages/backend add backstage-grpc-playground-backend

Usage

Register the plugin in backend

Create a new file packages/backend/src/plugins/grpc-playground.ts

// packages/backend/src/plugins/grpc-playground.ts
import { ScmIntegrations } from '@backstage/integration';
import { createRouter } from 'backstage-grpc-playground-backend';

import { Router } from 'express';
import { PluginEnvironment } from '../types';

export default async function createPlugin(
  env: PluginEnvironment,
): Promise<Router> {
  const { config, reader } = env;

  const integrations = ScmIntegrations.fromConfig(config);

  return await createRouter({
    logger: env.logger,
    reader,
    integrations,
    database: env.database,
  });
}

Register /grpc-playground path in backstage backend

// packages/backend/src/index.ts
import grpcPlayground from './plugins/grpc-playground';

async function main() {
  // other env
  const grpcPlaygroundEnv = useHotMemoize(module, () => createEnv('grpc-playground'));
  
  // init router
  // ...

  // register before notFoundHandler  
  apiRouter.use('/grpc-playground', await grpcPlayground(grpcPlaygroundEnv));

  // not found handler
  apiRouter.use(notFoundHandler());
}

Examples

See examples

Acknowledgements