npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cortexapps/backstage-backend-plugin

v1.6.7

Published

See the [Cortex Scorecard Plugin](https://www.npmjs.com/package/@cortexapps/backstage-plugin) for more details. The backend plugin will allow you to sync your Backstage services with Cortex asynchronously, set to any cron schedule of your choosing.

Downloads

321

Readme

Cortex Backend Plugin for Backstage

See the Cortex Scorecard Plugin for more details. The backend plugin will allow you to sync your Backstage services with Cortex asynchronously, set to any cron schedule of your choosing.

To start using the Backstage plugin and see a demo, please book a demo!

Setup and Integration (old backend model)

  1. In the packages/backend directory of your Backstage instance, add the plugin as a package.json dependency:
$ yarn add @cortexapps/backstage-backend-plugin
  1. Create a new file: packages/backend/src/plugins/cortex.ts:
import { PluginEnvironment } from '../types';
import { createRouter } from '@cortexapps/backstage-backend-plugin';

export default async function createPlugin(env: PluginEnvironment) {
  return await createRouter({
    discoveryApi: env.discovery,
    logger: env.logger,
    cronSchedule:
      env.config.getOptionalString('cortex.backend.cron') ??
      '0 3,7,11,15,19,23 * * *',
  });
}
  1. Update packages/backend/src/index.ts:
import cortex from './plugins/cortex';
...
const cortexEnv = useHotMemoize(module, () => createEnv('cortex'));
...
apiRouter.use('/cortex', await cortex(cortexEnv));
  1. Update app-config.yaml to add a new config under the proxy section:
'/cortex':
  target: ${CORTEX_BACKEND_HOST_URL}
  headers:
    Authorization: Bearer ${CORTEX_TOKEN}
  1. (Optional) You can choose to have the entity sync cron job use gzip to compress the entities by updating cortex.ts from step 2. You must also update the Backstage HTTP proxy to allow the Content-Encoding header.
import { PluginEnvironment } from '../types';
import { createRouter } from '@cortexapps/backstage-backend-plugin';

export default async function createPlugin(env: PluginEnvironment) {
  return await createRouter({
    discoveryApi: env.discovery,
    logger: env.logger,
    syncWithGzip: true,
    cronSchedule:
      env.config.getOptionalString('cortex.backend.cron') ??
      '0 3,7,11,15,19,23 * * *',
  });
}
proxy:
  '/cortex':
    target: ${CORTEX_BACKEND_HOST_URL}
    headers:
      Authorization: Bearer ${CORTEX_TOKEN}
    allowedHeaders:
      - Content-Encoding

Setup and Integration (new backend model)

  1. In the packages/backend directory of your Backstage instance, add the plugin as a package.json dependency:
$ yarn add @cortexapps/backstage-backend-plugin
  1. Update packages/backend/src/index.ts:
import cortexPlugin from '@cortexapps/backstage-backend-plugin';
...
const backend = createBackend();
...
backend.add(cortexPlugin)
...
backend.start()
  1. Update app-config.yaml to add a new config under the proxy.endpoints section:
proxy:
  endpoints:
    '/cortex':
      target: ${CORTEX_BACKEND_HOST_URL}
      headers:
        Authorization: Bearer ${CORTEX_TOKEN}
  1. (Optional) You may further configure entity sync cron job to set a custom schedule or use gzip to compress the entities by adding appropriate configuration properties. If enabling gzip, you must also update the Backstage HTTP proxy to allow the Content-Encoding header.
cortex:
  syncWithGzip: true
  backend:
    cron: 0 * * * * # every hour
---
proxy:
  endpoints:
    '/cortex':
      target: ${CORTEX_BACKEND_HOST_URL}
      headers:
        Authorization: Bearer ${CORTEX_TOKEN}
      allowedHeaders:
        - Content-Encoding
  1. (Optional) If you wish to make use of custom mappings via the ExtensionsApi in @cortexapps/backstage-plugin-extensions, you must configure a module to supply an implementation of this API to the Cortex plugin. Implementing the ExtensionsApi interface is discussed further in the cortexapps/backstage-plugin repo. The official Backstage documentation suggests first creating a new package for the module using yarn new and selecting backend-module. With a moduleId of extension-api the full package should be created at /modules/cortex-backend-module-extension-api. In module.ts of the new package, create a module which supplies your custom implementation of ExtensionApi:
// src/module.ts
import { createBackendModule } from '@backstage/backend-plugin-api';
import { cortexExtensionApiExtensionPoint } from '@cortexapps/backstage-plugin-extensions';
import { MyExtensionApiImpl } from `./MyExtensionApiImpl`;

export const cortexModuleExtensionApiProvider = createBackendModule({
  pluginId: 'cortex-backend',
  moduleId: 'my-extension-api',
  register(env) {
    env.registerInit({
      deps: {
        cortexBackend: cortexExtensionApiExtensionPoint,
      },
      async init({ cortexBackend }) {
        cortexBackend.setExtensionApi(new MyExtensionApiImpl());
      },
    });
  },
});

Export the module from index.ts:

// src/index.ts
export { cortexModuleExtensionApiProvider as default } from './module';

And finally add the extension to the backend in packages/backend/src/index.ts after the Cortex plugin itself:

backend.add(cortexPlugin); // should already be present from step 2
backend.add(import('<your-module-package>'));

Alternatively, if you do not wish to separate the module into its own package, you can instantiate cortexModuleExtensionApiProvider as shown above and add it to the backend directly:

const cortexModuleExtensionApiProvider = createBackendModule({...})
...
backend.add(cortexModuleExtensionApiProvider);