diff --git a/.changeset/lazy-pugs-wash.md b/.changeset/lazy-pugs-wash.md new file mode 100644 index 0000000000..923ef5b116 --- /dev/null +++ b/.changeset/lazy-pugs-wash.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-app-node': minor +--- + +Added the `app` plugin node library, initially providing an extension point that can be used to configure a static fallback handler. diff --git a/plugins/app-node/.eslintrc.js b/plugins/app-node/.eslintrc.js new file mode 100644 index 0000000000..e2a53a6ad2 --- /dev/null +++ b/plugins/app-node/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/plugins/app-node/README.md b/plugins/app-node/README.md new file mode 100644 index 0000000000..5c606540c0 --- /dev/null +++ b/plugins/app-node/README.md @@ -0,0 +1,5 @@ +# @backstage/plugin-app-node + +Welcome to the Node.js library package for the app plugin! + +_This plugin was created through the Backstage CLI_ diff --git a/plugins/app-node/api-report.md b/plugins/app-node/api-report.md new file mode 100644 index 0000000000..504c9d48c1 --- /dev/null +++ b/plugins/app-node/api-report.md @@ -0,0 +1,16 @@ +## API Report File for "@backstage/plugin-app-node" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts +import { ExtensionPoint } from '@backstage/backend-plugin-api'; +import { Handler } from 'express'; + +// @public +export interface StaticFallbackHandlerExtensionPoint { + setStaticFallbackHandler(handler: Handler): void; +} + +// @public +export const staticFallbackHandlerExtensionPoint: ExtensionPoint; +``` diff --git a/plugins/app-node/package.json b/plugins/app-node/package.json new file mode 100644 index 0000000000..9caff82e9d --- /dev/null +++ b/plugins/app-node/package.json @@ -0,0 +1,34 @@ +{ + "name": "@backstage/plugin-app-node", + "description": "Node.js library for the app plugin", + "version": "0.0.0", + "main": "src/index.ts", + "types": "src/index.ts", + "license": "Apache-2.0", + "publishConfig": { + "access": "public", + "main": "dist/index.cjs.js", + "types": "dist/index.d.ts" + }, + "backstage": { + "role": "node-library" + }, + "scripts": { + "build": "backstage-cli package build", + "lint": "backstage-cli package lint", + "test": "backstage-cli package test", + "clean": "backstage-cli package clean", + "prepack": "backstage-cli package prepack", + "postpack": "backstage-cli package postpack" + }, + "devDependencies": { + "@backstage/cli": "workspace:^" + }, + "files": [ + "dist" + ], + "dependencies": { + "@backstage/backend-plugin-api": "workspace:^", + "express": "^4.18.2" + } +} diff --git a/plugins/app-node/src/extensions.ts b/plugins/app-node/src/extensions.ts new file mode 100644 index 0000000000..6a75a5b791 --- /dev/null +++ b/plugins/app-node/src/extensions.ts @@ -0,0 +1,52 @@ +/* + * Copyright 2023 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 { createExtensionPoint } from '@backstage/backend-plugin-api'; +import { Handler } from 'express'; + +/** + * The interface for {@link staticFallbackHandlerExtensionPoint}. + * + * @public + */ +export interface StaticFallbackHandlerExtensionPoint { + /** + * Sets the static fallback handler. This can only be done once. + */ + setStaticFallbackHandler(handler: Handler): void; +} + +/** + * An extension point the exposes the ability to configure a static fallback handler for the app backend. + * + * The static fallback handler is a request handler to handle requests for static content that is not + * present in the app bundle. + * + * This can be used to avoid issues with clients on older deployment versions trying to access lazy + * loaded content that is no longer present. Typically the requests would fall back to a long-term + * object store where all recently deployed versions of the app are present. + * + * Another option is to provide a `database` that will take care of storing the static assets instead. + * + * If both `database` and `staticFallbackHandler` are provided, the `database` will attempt to serve + * static assets first, and if they are not found, the `staticFallbackHandler` will be called. + * + * @public + */ +export const staticFallbackHandlerExtensionPoint = + createExtensionPoint({ + id: 'app.staticFallbackHandler', + }); diff --git a/plugins/app-node/src/index.ts b/plugins/app-node/src/index.ts new file mode 100644 index 0000000000..c5189fa8b9 --- /dev/null +++ b/plugins/app-node/src/index.ts @@ -0,0 +1,26 @@ +/* + * Copyright 2023 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. + */ + +/** + * Node.js library for the app plugin. + * + * @packageDocumentation + */ + +export { + staticFallbackHandlerExtensionPoint, + type StaticFallbackHandlerExtensionPoint, +} from './extensions'; diff --git a/plugins/app-node/src/setupTests.ts b/plugins/app-node/src/setupTests.ts new file mode 100644 index 0000000000..4b9026cde5 --- /dev/null +++ b/plugins/app-node/src/setupTests.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2023 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. + */ +export {}; diff --git a/yarn.lock b/yarn.lock index f628161240..d18e8fbc66 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4657,6 +4657,16 @@ __metadata: languageName: unknown linkType: soft +"@backstage/plugin-app-node@workspace:^, @backstage/plugin-app-node@workspace:plugins/app-node": + version: 0.0.0-use.local + resolution: "@backstage/plugin-app-node@workspace:plugins/app-node" + dependencies: + "@backstage/backend-plugin-api": "workspace:^" + "@backstage/cli": "workspace:^" + express: ^4.18.2 + languageName: unknown + linkType: soft + "@backstage/plugin-auth-backend@workspace:^, @backstage/plugin-auth-backend@workspace:plugins/auth-backend": version: 0.0.0-use.local resolution: "@backstage/plugin-auth-backend@workspace:plugins/auth-backend"