Add backend README

Signed-off-by: josh <josh.timmons@hashicorp.com>
This commit is contained in:
josh
2023-06-04 18:32:19 -04:00
parent 520e984280
commit c0f49cec77
5 changed files with 63 additions and 34 deletions
+45 -9
View File
@@ -1,14 +1,50 @@
# nomad
# @backstage/plugin-nomad-backend
Welcome to the nomad backend plugin!
A backend for Nomad, this plugin exposes a service with routes that are used by the `@backstage/plugin-nomad` plugin to query Job and Group information from a Nomad API.
_This plugin was created through the Backstage CLI_
## Set Up
## Getting started
1. Install the plugin using:
Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn
start` in the root directory, and then navigating to [/nomad-backend](http://localhost:3000/nomad-backend).
```bash
# From your Backstage root directory
yarn add --cwd packages/backend @backstage/plugin-nomad-backend
```
You can also serve the plugin in isolation by running `yarn start` in the plugin directory.
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads.
It is only meant for local development, and the setup for it can be found inside the [/dev](/dev) directory.
2. Create a `nomad.ts` file inside `packages/backend/src/plugins/`:
```typescript
import { createRouter } from '@backstage/plugin-nomad-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
export default async function createPlugin(
props: PluginEnvironment,
): Promise<Router> {
return await createRouter(props);
}
```
3. Modify your `packages/backend/src/index.ts` to include:
```diff
...
import { Config } from '@backstage/config';
import app from './plugins/app';
+import nomad from './plugins/nomad';
...
async function main() {
...
const authEnv = useHotMemoize(module, () => createEnv('auth'));
+ const nomadEnv = useHotMemoize(module, () => createEnv('nomad'));
...
const apiRouter = Router();
apiRouter.use('/catalog', await catalog(catalogEnv));
+ apiRouter.use('/nomad', await nomad(nomadEnv));
```
Note: for this backend to work, the `nomad` configuration described in the README of `@backstage/plugin-nomad` must be configured.
@@ -18,12 +18,14 @@ import express from 'express';
import request from 'supertest';
import { createRouter } from './router';
import { ConfigReader } from '@backstage/config';
describe('createRouter', () => {
let app: express.Express;
beforeAll(async () => {
const router = await createRouter({
config: new ConfigReader({}),
logger: getVoidLogger(),
});
app = express().use(router);