@backstage/plugin-app-backend 0.3.48-next.1 → 0.3.48-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @backstage/plugin-app-backend
2
2
 
3
+ ## 0.3.48-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - d564ad142b17: Migrated the alpha `appBackend` export to use static configuration and extension points rather than accepting options.
8
+ - Updated dependencies
9
+ - @backstage/plugin-app-node@0.1.0-next.0
10
+ - @backstage/backend-plugin-api@0.6.0-next.2
11
+ - @backstage/backend-common@0.19.2-next.2
12
+ - @backstage/config-loader@1.4.0-next.1
13
+
3
14
  ## 0.3.48-next.1
4
15
 
5
16
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-app-backend",
3
- "version": "0.3.48-next.1",
3
+ "version": "0.3.48-next.2",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/config.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Copyright 2023 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export interface Config {
18
+ app?: {
19
+ /**
20
+ * The name of the app package (in most Backstage repositories, this is the
21
+ * "name" field in `packages/app/package.json`) that content should be served
22
+ * from. The same app package should be added as a dependency to the backend
23
+ * package in order for it to be accessible at runtime.
24
+ *
25
+ * In a typical setup with a single app package, this will default to 'app'.
26
+ */
27
+ packageName?: string;
28
+
29
+ /**
30
+ * Disables the configuration injection. This can be useful if you're running in an environment
31
+ * with a read-only filesystem, or for some other reason don't want configuration to be injected.
32
+ *
33
+ * Note that this will cause the configuration used when building the app bundle to be used, unless
34
+ * a separate configuration loading strategy is set up.
35
+ *
36
+ * This also disables configuration injection though `APP_CONFIG_` environment variables.
37
+ */
38
+ disableConfigInjection?: boolean;
39
+
40
+ /**
41
+ * By default the app backend plugin will cache previously deployed static assets in the database.
42
+ * If you disable this, it is recommended to set a `staticFallbackHandler` instead.
43
+ */
44
+ disableStaticFallbackCache?: boolean;
45
+ };
46
+ }
package/dist/alpha.cjs.js CHANGED
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var backendPluginApi = require('@backstage/backend-plugin-api');
6
- var router = require('./cjs/router-78e92a6f.cjs.js');
6
+ var router = require('./cjs/router-62f9e896.cjs.js');
7
7
  var backendCommon = require('@backstage/backend-common');
8
+ var pluginAppNode = require('@backstage/plugin-app-node');
8
9
  require('helmet');
9
10
  require('express');
10
11
  require('express-promise-router');
@@ -15,9 +16,20 @@ require('luxon');
15
16
  require('lodash/partition');
16
17
  require('globby');
17
18
 
18
- const appPlugin = backendPluginApi.createBackendPlugin((options) => ({
19
+ const appPlugin = backendPluginApi.createBackendPlugin({
19
20
  pluginId: "app",
20
21
  register(env) {
22
+ let staticFallbackHandler;
23
+ env.registerExtensionPoint(pluginAppNode.staticFallbackHandlerExtensionPoint, {
24
+ setStaticFallbackHandler(handler) {
25
+ if (staticFallbackHandler) {
26
+ throw new Error(
27
+ "Attempted to install a static fallback handler for the app-backend twice"
28
+ );
29
+ }
30
+ staticFallbackHandler = handler;
31
+ }
32
+ });
21
33
  env.registerInit({
22
34
  deps: {
23
35
  logger: backendPluginApi.coreServices.logger,
@@ -26,26 +38,21 @@ const appPlugin = backendPluginApi.createBackendPlugin((options) => ({
26
38
  httpRouter: backendPluginApi.coreServices.httpRouter
27
39
  },
28
40
  async init({ logger, config, database, httpRouter }) {
29
- const {
30
- appPackageName,
31
- staticFallbackHandler,
32
- disableConfigInjection,
33
- disableStaticFallbackCache
34
- } = options;
41
+ var _a;
42
+ const appPackageName = (_a = config.getOptionalString("app.packageName")) != null ? _a : "app";
35
43
  const winstonLogger = backendCommon.loggerToWinstonLogger(logger);
36
44
  const router$1 = await router.createRouter({
37
45
  logger: winstonLogger,
38
46
  config,
39
- database: disableStaticFallbackCache ? void 0 : database,
40
- appPackageName: appPackageName != null ? appPackageName : "app",
41
- staticFallbackHandler,
42
- disableConfigInjection
47
+ database,
48
+ appPackageName,
49
+ staticFallbackHandler
43
50
  });
44
51
  httpRouter.use(router$1);
45
52
  }
46
53
  });
47
54
  }
48
- }));
55
+ });
49
56
 
50
57
  exports.appPlugin = appPlugin;
51
58
  //# sourceMappingURL=alpha.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"alpha.cjs.js","sources":["../src/service/appPlugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport express from 'express';\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './router';\nimport { loggerToWinstonLogger } from '@backstage/backend-common';\n\n/** @alpha */\nexport type AppPluginOptions = {\n /**\n * The name of the app package (in most Backstage repositories, this is the\n * \"name\" field in `packages/app/package.json`) that content should be served\n * from. The same app package should be added as a dependency to the backend\n * package in order for it to be accessible at runtime.\n *\n * In a typical setup with a single app package, this will default to 'app'.\n */\n appPackageName?: string;\n\n /**\n * A request handler to handle requests for static content that are not present in the app bundle.\n *\n * This can be used to avoid issues with clients on older deployment versions trying to access lazy\n * loaded content that is no longer present. Typically the requests would fall back to a long-term\n * object store where all recently deployed versions of the app are present.\n *\n * Another option is to provide a `database` that will take care of storing the static assets instead.\n *\n * If both `database` and `staticFallbackHandler` are provided, the `database` will attempt to serve\n * static assets first, and if they are not found, the `staticFallbackHandler` will be called.\n */\n staticFallbackHandler?: express.Handler;\n\n /**\n * Disables the configuration injection. This can be useful if you're running in an environment\n * with a read-only filesystem, or for some other reason don't want configuration to be injected.\n *\n * Note that this will cause the configuration used when building the app bundle to be used, unless\n * a separate configuration loading strategy is set up.\n *\n * This also disables configuration injection though `APP_CONFIG_` environment variables.\n */\n disableConfigInjection?: boolean;\n\n /**\n * By default the app backend plugin will cache previously deployed static assets in the database.\n * If you disable this, it is recommended to set a `staticFallbackHandler` instead.\n */\n disableStaticFallbackCache?: boolean;\n};\n\n/**\n * The App plugin is responsible for serving the frontend app bundle and static assets.\n * @alpha\n */\nexport const appPlugin = createBackendPlugin((options: AppPluginOptions) => ({\n pluginId: 'app',\n register(env) {\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n database: coreServices.database,\n httpRouter: coreServices.httpRouter,\n },\n async init({ logger, config, database, httpRouter }) {\n const {\n appPackageName,\n staticFallbackHandler,\n disableConfigInjection,\n disableStaticFallbackCache,\n } = options;\n const winstonLogger = loggerToWinstonLogger(logger);\n\n const router = await createRouter({\n logger: winstonLogger,\n config,\n database: disableStaticFallbackCache ? undefined : database,\n appPackageName: appPackageName ?? 'app',\n staticFallbackHandler,\n disableConfigInjection,\n });\n httpRouter.use(router);\n },\n });\n },\n}));\n"],"names":["createBackendPlugin","coreServices","loggerToWinstonLogger","router","createRouter"],"mappings":";;;;;;;;;;;;;;;;;AAwEa,MAAA,SAAA,GAAYA,oCAAoB,CAAA,CAAC,OAA+B,MAAA;AAAA,EAC3E,QAAU,EAAA,KAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,MAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,YAAYA,6BAAa,CAAA,UAAA;AAAA,OAC3B;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,QAAQ,MAAQ,EAAA,QAAA,EAAU,YAAc,EAAA;AACnD,QAAM,MAAA;AAAA,UACJ,cAAA;AAAA,UACA,qBAAA;AAAA,UACA,sBAAA;AAAA,UACA,0BAAA;AAAA,SACE,GAAA,OAAA,CAAA;AACJ,QAAM,MAAA,aAAA,GAAgBC,oCAAsB,MAAM,CAAA,CAAA;AAElD,QAAM,MAAAC,QAAA,GAAS,MAAMC,mBAAa,CAAA;AAAA,UAChC,MAAQ,EAAA,aAAA;AAAA,UACR,MAAA;AAAA,UACA,QAAA,EAAU,6BAA6B,KAAY,CAAA,GAAA,QAAA;AAAA,UACnD,gBAAgB,cAAkB,IAAA,IAAA,GAAA,cAAA,GAAA,KAAA;AAAA,UAClC,qBAAA;AAAA,UACA,sBAAA;AAAA,SACD,CAAA,CAAA;AACD,QAAA,UAAA,CAAW,IAAID,QAAM,CAAA,CAAA;AAAA,OACvB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAE,CAAA;;;;"}
1
+ {"version":3,"file":"alpha.cjs.js","sources":["../src/service/appPlugin.ts"],"sourcesContent":["/*\n * Copyright 2022 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport express from 'express';\nimport {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouter } from './router';\nimport { loggerToWinstonLogger } from '@backstage/backend-common';\nimport { staticFallbackHandlerExtensionPoint } from '@backstage/plugin-app-node';\n\n/**\n * The App plugin is responsible for serving the frontend app bundle and static assets.\n * @alpha\n */\nexport const appPlugin = createBackendPlugin({\n pluginId: 'app',\n register(env) {\n let staticFallbackHandler: express.Handler | undefined;\n\n env.registerExtensionPoint(staticFallbackHandlerExtensionPoint, {\n setStaticFallbackHandler(handler) {\n if (staticFallbackHandler) {\n throw new Error(\n 'Attempted to install a static fallback handler for the app-backend twice',\n );\n }\n staticFallbackHandler = handler;\n },\n });\n\n env.registerInit({\n deps: {\n logger: coreServices.logger,\n config: coreServices.rootConfig,\n database: coreServices.database,\n httpRouter: coreServices.httpRouter,\n },\n async init({ logger, config, database, httpRouter }) {\n const appPackageName =\n config.getOptionalString('app.packageName') ?? 'app';\n const winstonLogger = loggerToWinstonLogger(logger);\n\n const router = await createRouter({\n logger: winstonLogger,\n config,\n database,\n appPackageName,\n staticFallbackHandler,\n });\n httpRouter.use(router);\n },\n });\n },\n});\n"],"names":["createBackendPlugin","staticFallbackHandlerExtensionPoint","coreServices","loggerToWinstonLogger","router","createRouter"],"mappings":";;;;;;;;;;;;;;;;;;AA6BO,MAAM,YAAYA,oCAAoB,CAAA;AAAA,EAC3C,QAAU,EAAA,KAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAI,IAAA,qBAAA,CAAA;AAEJ,IAAA,GAAA,CAAI,uBAAuBC,iDAAqC,EAAA;AAAA,MAC9D,yBAAyB,OAAS,EAAA;AAChC,QAAA,IAAI,qBAAuB,EAAA;AACzB,UAAA,MAAM,IAAI,KAAA;AAAA,YACR,0EAAA;AAAA,WACF,CAAA;AAAA,SACF;AACA,QAAwB,qBAAA,GAAA,OAAA,CAAA;AAAA,OAC1B;AAAA,KACD,CAAA,CAAA;AAED,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,QAAQC,6BAAa,CAAA,MAAA;AAAA,QACrB,QAAQA,6BAAa,CAAA,UAAA;AAAA,QACrB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,YAAYA,6BAAa,CAAA,UAAA;AAAA,OAC3B;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,QAAQ,MAAQ,EAAA,QAAA,EAAU,YAAc,EAAA;AApD3D,QAAA,IAAA,EAAA,CAAA;AAqDQ,QAAA,MAAM,cACJ,GAAA,CAAA,EAAA,GAAA,MAAA,CAAO,iBAAkB,CAAA,iBAAiB,MAA1C,IAA+C,GAAA,EAAA,GAAA,KAAA,CAAA;AACjD,QAAM,MAAA,aAAA,GAAgBC,oCAAsB,MAAM,CAAA,CAAA;AAElD,QAAM,MAAAC,QAAA,GAAS,MAAMC,mBAAa,CAAA;AAAA,UAChC,MAAQ,EAAA,aAAA;AAAA,UACR,MAAA;AAAA,UACA,QAAA;AAAA,UACA,cAAA;AAAA,UACA,qBAAA;AAAA,SACD,CAAA,CAAA;AACD,QAAA,UAAA,CAAW,IAAID,QAAM,CAAA,CAAA;AAAA,OACvB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF,CAAC;;;;"}
package/dist/alpha.d.ts CHANGED
@@ -1,50 +1,9 @@
1
1
  import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
- import express from 'express';
3
2
 
4
- /** @alpha */
5
- type AppPluginOptions = {
6
- /**
7
- * The name of the app package (in most Backstage repositories, this is the
8
- * "name" field in `packages/app/package.json`) that content should be served
9
- * from. The same app package should be added as a dependency to the backend
10
- * package in order for it to be accessible at runtime.
11
- *
12
- * In a typical setup with a single app package, this will default to 'app'.
13
- */
14
- appPackageName?: string;
15
- /**
16
- * A request handler to handle requests for static content that are not present in the app bundle.
17
- *
18
- * This can be used to avoid issues with clients on older deployment versions trying to access lazy
19
- * loaded content that is no longer present. Typically the requests would fall back to a long-term
20
- * object store where all recently deployed versions of the app are present.
21
- *
22
- * Another option is to provide a `database` that will take care of storing the static assets instead.
23
- *
24
- * If both `database` and `staticFallbackHandler` are provided, the `database` will attempt to serve
25
- * static assets first, and if they are not found, the `staticFallbackHandler` will be called.
26
- */
27
- staticFallbackHandler?: express.Handler;
28
- /**
29
- * Disables the configuration injection. This can be useful if you're running in an environment
30
- * with a read-only filesystem, or for some other reason don't want configuration to be injected.
31
- *
32
- * Note that this will cause the configuration used when building the app bundle to be used, unless
33
- * a separate configuration loading strategy is set up.
34
- *
35
- * This also disables configuration injection though `APP_CONFIG_` environment variables.
36
- */
37
- disableConfigInjection?: boolean;
38
- /**
39
- * By default the app backend plugin will cache previously deployed static assets in the database.
40
- * If you disable this, it is recommended to set a `staticFallbackHandler` instead.
41
- */
42
- disableStaticFallbackCache?: boolean;
43
- };
44
3
  /**
45
4
  * The App plugin is responsible for serving the frontend app bundle and static assets.
46
5
  * @alpha
47
6
  */
48
- declare const appPlugin: (options: AppPluginOptions) => _backstage_backend_plugin_api.BackendFeature;
7
+ declare const appPlugin: () => _backstage_backend_plugin_api.BackendFeature;
49
8
 
50
- export { AppPluginOptions, appPlugin };
9
+ export { appPlugin };
@@ -221,7 +221,12 @@ function createStaticAssetMiddleware(store) {
221
221
  }
222
222
 
223
223
  async function createRouter(options) {
224
+ var _a;
224
225
  const { config, logger, appPackageName, staticFallbackHandler } = options;
226
+ const disableConfigInjection = (_a = options.disableConfigInjection) != null ? _a : config.getOptionalBoolean("app.disableConfigInjection");
227
+ const disableStaticFallbackCache = config.getOptionalBoolean(
228
+ "app.disableStaticFallbackCache"
229
+ );
225
230
  const appDistDir = backendCommon.resolvePackagePath(appPackageName, "dist");
226
231
  const staticDir = path.resolve(appDistDir, "static");
227
232
  if (!await fs__default["default"].pathExists(staticDir)) {
@@ -233,7 +238,7 @@ async function createRouter(options) {
233
238
  return Router__default["default"]();
234
239
  }
235
240
  logger.info(`Serving static app content from ${appDistDir}`);
236
- if (!options.disableConfigInjection) {
241
+ if (!disableConfigInjection) {
237
242
  const appConfigs = await readConfigs({
238
243
  config,
239
244
  appDistDir,
@@ -251,7 +256,7 @@ async function createRouter(options) {
251
256
  }
252
257
  })
253
258
  );
254
- if (options.database) {
259
+ if (options.database && !disableStaticFallbackCache) {
255
260
  const store = await StaticAssetsStore.create({
256
261
  logger,
257
262
  database: options.database
@@ -288,4 +293,4 @@ async function createRouter(options) {
288
293
  }
289
294
 
290
295
  exports.createRouter = createRouter;
291
- //# sourceMappingURL=router-78e92a6f.cjs.js.map
296
+ //# sourceMappingURL=router-62f9e896.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"router-78e92a6f.cjs.js","sources":["../../src/lib/config.ts","../../src/lib/assets/StaticAssetsStore.ts","../../src/lib/assets/findStaticAssets.ts","../../src/lib/headers.ts","../../src/lib/assets/createStaticAssetMiddleware.ts","../../src/service/router.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs-extra';\nimport { resolve as resolvePath } from 'path';\nimport { Logger } from 'winston';\nimport { AppConfig, Config } from '@backstage/config';\nimport { JsonObject } from '@backstage/types';\nimport { loadConfigSchema, readEnvConfig } from '@backstage/config-loader';\n\ntype InjectOptions = {\n appConfigs: AppConfig[];\n // Directory of the static JS files to search for file to inject\n staticDir: string;\n logger: Logger;\n};\n\n/**\n * Injects configs into the app bundle, replacing any existing injected config.\n */\nexport async function injectConfig(options: InjectOptions) {\n const { staticDir, logger, appConfigs } = options;\n\n const files = await fs.readdir(staticDir);\n const jsFiles = files.filter(file => file.endsWith('.js'));\n\n const escapedData = JSON.stringify(appConfigs).replace(/(\"|'|\\\\)/g, '\\\\$1');\n const injected = `/*__APP_INJECTED_CONFIG_MARKER__*/\"${escapedData}\"/*__INJECTED_END__*/`;\n\n for (const jsFile of jsFiles) {\n const path = resolvePath(staticDir, jsFile);\n\n const content = await fs.readFile(path, 'utf8');\n if (content.includes('__APP_INJECTED_RUNTIME_CONFIG__')) {\n logger.info(`Injecting env config into ${jsFile}`);\n\n const newContent = content.replace(\n '\"__APP_INJECTED_RUNTIME_CONFIG__\"',\n injected,\n );\n await fs.writeFile(path, newContent, 'utf8');\n return;\n } else if (content.includes('__APP_INJECTED_CONFIG_MARKER__')) {\n logger.info(`Replacing injected env config in ${jsFile}`);\n\n const newContent = content.replace(\n /\\/\\*__APP_INJECTED_CONFIG_MARKER__\\*\\/.*\\/\\*__INJECTED_END__\\*\\//,\n injected,\n );\n await fs.writeFile(path, newContent, 'utf8');\n return;\n }\n }\n logger.info('Env config not injected');\n}\n\ntype ReadOptions = {\n env: { [name: string]: string | undefined };\n appDistDir: string;\n config: Config;\n};\n\n/**\n * Read config from environment and process the backend config using the\n * schema that is embedded in the frontend build.\n */\nexport async function readConfigs(options: ReadOptions): Promise<AppConfig[]> {\n const { env, appDistDir, config } = options;\n\n const appConfigs = readEnvConfig(env);\n\n const schemaPath = resolvePath(appDistDir, '.config-schema.json');\n if (await fs.pathExists(schemaPath)) {\n const serializedSchema = await fs.readJson(schemaPath);\n\n try {\n const schema = await loadConfigSchema({ serialized: serializedSchema });\n\n const frontendConfigs = await schema.process(\n [{ data: config.get() as JsonObject, context: 'app' }],\n { visibility: ['frontend'], withDeprecatedKeys: true },\n );\n appConfigs.push(...frontendConfigs);\n } catch (error) {\n throw new Error(\n 'Invalid app bundle schema. If this error is unexpected you need to run `yarn build` in the app. ' +\n `If that doesn't help you should make sure your config schema is correct and rebuild the app bundle again. ` +\n `Caused by the following schema error, ${error}`,\n );\n }\n }\n\n return appConfigs;\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n PluginDatabaseManager,\n resolvePackagePath,\n} from '@backstage/backend-common';\nimport { Knex } from 'knex';\nimport { Logger } from 'winston';\nimport { DateTime } from 'luxon';\nimport partition from 'lodash/partition';\nimport { StaticAsset, StaticAssetInput, StaticAssetProvider } from './types';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-app-backend',\n 'migrations',\n);\n\ninterface StaticAssetRow {\n path: string;\n content: Buffer;\n last_modified_at: Date;\n}\n\n/** @internal */\nexport interface StaticAssetsStoreOptions {\n database: PluginDatabaseManager;\n logger: Logger;\n}\n\n/**\n * A storage for static assets that are assumed to be immutable.\n *\n * @internal\n */\nexport class StaticAssetsStore implements StaticAssetProvider {\n #db: Knex;\n #logger: Logger;\n\n static async create(options: StaticAssetsStoreOptions) {\n const { database } = options;\n const client = await database.getClient();\n\n if (!database.migrations?.skip) {\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new StaticAssetsStore(client, options.logger);\n }\n\n private constructor(client: Knex, logger: Logger) {\n this.#db = client;\n this.#logger = logger;\n }\n\n /**\n * Store the provided assets.\n *\n * If an asset for a given path already exists the modification time will be\n * updated, but the contents will not.\n */\n async storeAssets(assets: StaticAssetInput[]) {\n const existingRows = await this.#db<StaticAssetRow>(\n 'static_assets_cache',\n ).whereIn(\n 'path',\n assets.map(a => a.path),\n );\n const existingAssetPaths = new Set(existingRows.map(r => r.path));\n\n const [modified, added] = partition(assets, asset =>\n existingAssetPaths.has(asset.path),\n );\n\n this.#logger.info(\n `Storing ${modified.length} updated assets and ${added.length} new assets`,\n );\n\n await this.#db('static_assets_cache')\n .update({\n last_modified_at: this.#db.fn.now(),\n })\n .whereIn(\n 'path',\n modified.map(a => a.path),\n );\n\n for (const asset of added) {\n // We ignore conflicts with other nodes, it doesn't matter if someone else\n // added the same asset just before us.\n await this.#db('static_assets_cache')\n .insert({\n path: asset.path,\n content: await asset.content(),\n })\n .onConflict('path')\n .ignore();\n }\n }\n\n /**\n * Retrieve an asset from the store with the given path.\n */\n async getAsset(path: string): Promise<StaticAsset | undefined> {\n const [row] = await this.#db<StaticAssetRow>('static_assets_cache').where({\n path,\n });\n if (!row) {\n return undefined;\n }\n return {\n path: row.path,\n content: row.content,\n lastModifiedAt:\n typeof row.last_modified_at === 'string'\n ? DateTime.fromSQL(row.last_modified_at, { zone: 'UTC' }).toJSDate()\n : row.last_modified_at,\n };\n }\n\n /**\n * Delete any assets from the store whose modification time is older than the max age.\n */\n async trimAssets(options: { maxAgeSeconds: number }) {\n const { maxAgeSeconds } = options;\n await this.#db<StaticAssetRow>('static_assets_cache')\n .where(\n 'last_modified_at',\n '<=',\n this.#db.client.config.client.includes('sqlite3')\n ? this.#db.raw(`datetime('now', ?)`, [`-${maxAgeSeconds} seconds`])\n : this.#db.raw(`now() + interval '${-maxAgeSeconds} seconds'`),\n )\n .delete();\n }\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { StaticAssetInput } from './types';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\n\n/**\n * Finds all static assets within a directory\n *\n * @internal\n */\nexport async function findStaticAssets(\n staticDir: string,\n): Promise<StaticAssetInput[]> {\n const assetPaths = await globby('**/*', {\n ignore: ['**/*.map'], // Ignore source maps since they're quite large\n cwd: staticDir,\n dot: true,\n });\n\n return assetPaths.map(path => ({\n path,\n content: async () => fs.readFile(resolveSafeChildPath(staticDir, path)),\n }));\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const CACHE_CONTROL_NO_CACHE = 'no-store, max-age=0';\nexport const CACHE_CONTROL_MAX_CACHE = 'public, max-age=1209600'; // 14 days\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { extname } from 'path';\nimport { RequestHandler } from 'express';\nimport { StaticAssetProvider } from './types';\nimport { CACHE_CONTROL_MAX_CACHE } from '../headers';\n\n/**\n * Creates a middleware that serves static assets from a static asset provider\n *\n * @internal\n */\nexport function createStaticAssetMiddleware(\n store: StaticAssetProvider,\n): RequestHandler {\n return (req, res, next) => {\n if (req.method !== 'GET' && req.method !== 'HEAD') {\n next();\n return;\n }\n\n // Let's not assume we're in promise-router\n Promise.resolve(\n (async () => {\n // Drop leading slashes from the incoming path\n const path = req.path.startsWith('/') ? req.path.slice(1) : req.path;\n\n const asset = await store.getAsset(path);\n if (!asset) {\n next();\n return;\n }\n\n // Set the Content-Type header, falling back to octet-stream\n const ext = extname(asset.path);\n if (ext) {\n res.type(ext);\n } else {\n res.type('bin');\n }\n\n // Same as our express.static override\n res.setHeader('Cache-Control', CACHE_CONTROL_MAX_CACHE);\n res.setHeader('Last-Modified', asset.lastModifiedAt.toUTCString());\n\n res.send(asset.content);\n })(),\n ).catch(next);\n };\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n notFoundHandler,\n PluginDatabaseManager,\n resolvePackagePath,\n} from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport helmet from 'helmet';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport fs from 'fs-extra';\nimport { resolve as resolvePath } from 'path';\nimport { Logger } from 'winston';\nimport { injectConfig, readConfigs } from '../lib/config';\nimport {\n StaticAssetsStore,\n findStaticAssets,\n createStaticAssetMiddleware,\n} from '../lib/assets';\nimport {\n CACHE_CONTROL_MAX_CACHE,\n CACHE_CONTROL_NO_CACHE,\n} from '../lib/headers';\n\n// express uses mime v1 while we only have types for mime v2\ntype Mime = { lookup(arg0: string): string };\n\n/** @public */\nexport interface RouterOptions {\n config: Config;\n logger: Logger;\n\n /**\n * If a database is provided it will be used to cache previously deployed static assets.\n *\n * This is a built-in alternative to using a `staticFallbackHandler`.\n */\n database?: PluginDatabaseManager;\n\n /**\n * The name of the app package that content should be served from. The same app package should be\n * added as a dependency to the backend package in order for it to be accessible at runtime.\n *\n * In a typical setup with a single app package this would be set to 'app'.\n */\n appPackageName: string;\n\n /**\n * A request handler to handle requests for static content that are not present in the app bundle.\n *\n * This can be used to avoid issues with clients on older deployment versions trying to access lazy\n * loaded content that is no longer present. Typically the requests would fall back to a long-term\n * object store where all recently deployed versions of the app are present.\n *\n * Another option is to provide a `database` that will take care of storing the static assets instead.\n *\n * If both `database` and `staticFallbackHandler` are provided, the `database` will attempt to serve\n * static assets first, and if they are not found, the `staticFallbackHandler` will be called.\n */\n staticFallbackHandler?: express.Handler;\n\n /**\n * Disables the configuration injection. This can be useful if you're running in an environment\n * with a read-only filesystem, or for some other reason don't want configuration to be injected.\n *\n * Note that this will cause the configuration used when building the app bundle to be used, unless\n * a separate configuration loading strategy is set up.\n *\n * This also disables configuration injection though `APP_CONFIG_` environment variables.\n */\n disableConfigInjection?: boolean;\n}\n\n/** @public */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { config, logger, appPackageName, staticFallbackHandler } = options;\n\n const appDistDir = resolvePackagePath(appPackageName, 'dist');\n const staticDir = resolvePath(appDistDir, 'static');\n\n if (!(await fs.pathExists(staticDir))) {\n if (process.env.NODE_ENV === 'production') {\n logger.error(\n `Can't serve static app content from ${staticDir}, directory doesn't exist`,\n );\n }\n\n return Router();\n }\n\n logger.info(`Serving static app content from ${appDistDir}`);\n\n if (!options.disableConfigInjection) {\n const appConfigs = await readConfigs({\n config,\n appDistDir,\n env: process.env,\n });\n\n await injectConfig({ appConfigs, logger, staticDir });\n }\n\n const router = Router();\n\n router.use(helmet.frameguard({ action: 'deny' }));\n\n // Use a separate router for static content so that a fallback can be provided by backend\n const staticRouter = Router();\n staticRouter.use(\n express.static(resolvePath(appDistDir, 'static'), {\n setHeaders: res => {\n res.setHeader('Cache-Control', CACHE_CONTROL_MAX_CACHE);\n },\n }),\n );\n\n if (options.database) {\n const store = await StaticAssetsStore.create({\n logger,\n database: options.database,\n });\n\n const assets = await findStaticAssets(staticDir);\n await store.storeAssets(assets);\n // Remove any assets that are older than 7 days\n await store.trimAssets({ maxAgeSeconds: 60 * 60 * 24 * 7 });\n\n staticRouter.use(createStaticAssetMiddleware(store));\n }\n\n if (staticFallbackHandler) {\n staticRouter.use(staticFallbackHandler);\n }\n staticRouter.use(notFoundHandler());\n\n router.use('/static', staticRouter);\n router.use(\n express.static(appDistDir, {\n setHeaders: (res, path) => {\n // The Cache-Control header instructs the browser to not cache html files since it might\n // link to static assets from recently deployed versions.\n if (\n (express.static.mime as unknown as Mime).lookup(path) === 'text/html'\n ) {\n res.setHeader('Cache-Control', CACHE_CONTROL_NO_CACHE);\n }\n },\n }),\n );\n router.get('/*', (_req, res) => {\n res.sendFile(resolvePath(appDistDir, 'index.html'), {\n headers: {\n // The Cache-Control header instructs the browser to not cache the index.html since it might\n // link to static assets from recently deployed versions.\n 'cache-control': CACHE_CONTROL_NO_CACHE,\n },\n });\n });\n\n return router;\n}\n"],"names":["fs","path","resolvePath","readEnvConfig","loadConfigSchema","resolvePackagePath","partition","DateTime","globby","resolveSafeChildPath","extname","Router","helmet","express","notFoundHandler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiCA,eAAsB,aAAa,OAAwB,EAAA;AACzD,EAAA,MAAM,EAAE,SAAA,EAAW,MAAQ,EAAA,UAAA,EAAe,GAAA,OAAA,CAAA;AAE1C,EAAA,MAAM,KAAQ,GAAA,MAAMA,sBAAG,CAAA,OAAA,CAAQ,SAAS,CAAA,CAAA;AACxC,EAAA,MAAM,UAAU,KAAM,CAAA,MAAA,CAAO,UAAQ,IAAK,CAAA,QAAA,CAAS,KAAK,CAAC,CAAA,CAAA;AAEzD,EAAA,MAAM,cAAc,IAAK,CAAA,SAAA,CAAU,UAAU,CAAE,CAAA,OAAA,CAAQ,aAAa,MAAM,CAAA,CAAA;AAC1E,EAAM,MAAA,QAAA,GAAW,sCAAsC,WAAW,CAAA,qBAAA,CAAA,CAAA;AAElE,EAAA,KAAA,MAAW,UAAU,OAAS,EAAA;AAC5B,IAAM,MAAAC,MAAA,GAAOC,YAAY,CA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;AAAA,GACH,CAAA;AACA,EAAA,MAAA,CAAO,GAAI,CAAA,IAAA,EAAM,CAAC,IAAA,EAAM,GAAQ,KAAA;AAC9B,IAAA,GAAA,CAAI,QAAS,CAAAX,YAAA,CAAY,UAAY,EAAA,YAAY,CAAG,EAAA;AAAA,MAClD,OAAS,EAAA;AAAA;AAAA;AAAA,QAGP,eAAiB,EAAA,sBAAA;AAAA,OACnB;AAAA,KACD,CAAA,CAAA;AAAA,GACF,CAAA,CAAA;AAED,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
1
+ {"version":3,"file":"router-62f9e896.cjs.js","sources":["../../src/lib/config.ts","../../src/lib/assets/StaticAssetsStore.ts","../../src/lib/assets/findStaticAssets.ts","../../src/lib/headers.ts","../../src/lib/assets/createStaticAssetMiddleware.ts","../../src/service/router.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs-extra';\nimport { resolve as resolvePath } from 'path';\nimport { Logger } from 'winston';\nimport { AppConfig, Config } from '@backstage/config';\nimport { JsonObject } from '@backstage/types';\nimport { loadConfigSchema, readEnvConfig } from '@backstage/config-loader';\n\ntype InjectOptions = {\n appConfigs: AppConfig[];\n // Directory of the static JS files to search for file to inject\n staticDir: string;\n logger: Logger;\n};\n\n/**\n * Injects configs into the app bundle, replacing any existing injected config.\n */\nexport async function injectConfig(options: InjectOptions) {\n const { staticDir, logger, appConfigs } = options;\n\n const files = await fs.readdir(staticDir);\n const jsFiles = files.filter(file => file.endsWith('.js'));\n\n const escapedData = JSON.stringify(appConfigs).replace(/(\"|'|\\\\)/g, '\\\\$1');\n const injected = `/*__APP_INJECTED_CONFIG_MARKER__*/\"${escapedData}\"/*__INJECTED_END__*/`;\n\n for (const jsFile of jsFiles) {\n const path = resolvePath(staticDir, jsFile);\n\n const content = await fs.readFile(path, 'utf8');\n if (content.includes('__APP_INJECTED_RUNTIME_CONFIG__')) {\n logger.info(`Injecting env config into ${jsFile}`);\n\n const newContent = content.replace(\n '\"__APP_INJECTED_RUNTIME_CONFIG__\"',\n injected,\n );\n await fs.writeFile(path, newContent, 'utf8');\n return;\n } else if (content.includes('__APP_INJECTED_CONFIG_MARKER__')) {\n logger.info(`Replacing injected env config in ${jsFile}`);\n\n const newContent = content.replace(\n /\\/\\*__APP_INJECTED_CONFIG_MARKER__\\*\\/.*\\/\\*__INJECTED_END__\\*\\//,\n injected,\n );\n await fs.writeFile(path, newContent, 'utf8');\n return;\n }\n }\n logger.info('Env config not injected');\n}\n\ntype ReadOptions = {\n env: { [name: string]: string | undefined };\n appDistDir: string;\n config: Config;\n};\n\n/**\n * Read config from environment and process the backend config using the\n * schema that is embedded in the frontend build.\n */\nexport async function readConfigs(options: ReadOptions): Promise<AppConfig[]> {\n const { env, appDistDir, config } = options;\n\n const appConfigs = readEnvConfig(env);\n\n const schemaPath = resolvePath(appDistDir, '.config-schema.json');\n if (await fs.pathExists(schemaPath)) {\n const serializedSchema = await fs.readJson(schemaPath);\n\n try {\n const schema = await loadConfigSchema({ serialized: serializedSchema });\n\n const frontendConfigs = await schema.process(\n [{ data: config.get() as JsonObject, context: 'app' }],\n { visibility: ['frontend'], withDeprecatedKeys: true },\n );\n appConfigs.push(...frontendConfigs);\n } catch (error) {\n throw new Error(\n 'Invalid app bundle schema. If this error is unexpected you need to run `yarn build` in the app. ' +\n `If that doesn't help you should make sure your config schema is correct and rebuild the app bundle again. ` +\n `Caused by the following schema error, ${error}`,\n );\n }\n }\n\n return appConfigs;\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n PluginDatabaseManager,\n resolvePackagePath,\n} from '@backstage/backend-common';\nimport { Knex } from 'knex';\nimport { Logger } from 'winston';\nimport { DateTime } from 'luxon';\nimport partition from 'lodash/partition';\nimport { StaticAsset, StaticAssetInput, StaticAssetProvider } from './types';\n\nconst migrationsDir = resolvePackagePath(\n '@backstage/plugin-app-backend',\n 'migrations',\n);\n\ninterface StaticAssetRow {\n path: string;\n content: Buffer;\n last_modified_at: Date;\n}\n\n/** @internal */\nexport interface StaticAssetsStoreOptions {\n database: PluginDatabaseManager;\n logger: Logger;\n}\n\n/**\n * A storage for static assets that are assumed to be immutable.\n *\n * @internal\n */\nexport class StaticAssetsStore implements StaticAssetProvider {\n #db: Knex;\n #logger: Logger;\n\n static async create(options: StaticAssetsStoreOptions) {\n const { database } = options;\n const client = await database.getClient();\n\n if (!database.migrations?.skip) {\n await client.migrate.latest({\n directory: migrationsDir,\n });\n }\n\n return new StaticAssetsStore(client, options.logger);\n }\n\n private constructor(client: Knex, logger: Logger) {\n this.#db = client;\n this.#logger = logger;\n }\n\n /**\n * Store the provided assets.\n *\n * If an asset for a given path already exists the modification time will be\n * updated, but the contents will not.\n */\n async storeAssets(assets: StaticAssetInput[]) {\n const existingRows = await this.#db<StaticAssetRow>(\n 'static_assets_cache',\n ).whereIn(\n 'path',\n assets.map(a => a.path),\n );\n const existingAssetPaths = new Set(existingRows.map(r => r.path));\n\n const [modified, added] = partition(assets, asset =>\n existingAssetPaths.has(asset.path),\n );\n\n this.#logger.info(\n `Storing ${modified.length} updated assets and ${added.length} new assets`,\n );\n\n await this.#db('static_assets_cache')\n .update({\n last_modified_at: this.#db.fn.now(),\n })\n .whereIn(\n 'path',\n modified.map(a => a.path),\n );\n\n for (const asset of added) {\n // We ignore conflicts with other nodes, it doesn't matter if someone else\n // added the same asset just before us.\n await this.#db('static_assets_cache')\n .insert({\n path: asset.path,\n content: await asset.content(),\n })\n .onConflict('path')\n .ignore();\n }\n }\n\n /**\n * Retrieve an asset from the store with the given path.\n */\n async getAsset(path: string): Promise<StaticAsset | undefined> {\n const [row] = await this.#db<StaticAssetRow>('static_assets_cache').where({\n path,\n });\n if (!row) {\n return undefined;\n }\n return {\n path: row.path,\n content: row.content,\n lastModifiedAt:\n typeof row.last_modified_at === 'string'\n ? DateTime.fromSQL(row.last_modified_at, { zone: 'UTC' }).toJSDate()\n : row.last_modified_at,\n };\n }\n\n /**\n * Delete any assets from the store whose modification time is older than the max age.\n */\n async trimAssets(options: { maxAgeSeconds: number }) {\n const { maxAgeSeconds } = options;\n await this.#db<StaticAssetRow>('static_assets_cache')\n .where(\n 'last_modified_at',\n '<=',\n this.#db.client.config.client.includes('sqlite3')\n ? this.#db.raw(`datetime('now', ?)`, [`-${maxAgeSeconds} seconds`])\n : this.#db.raw(`now() + interval '${-maxAgeSeconds} seconds'`),\n )\n .delete();\n }\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from 'fs-extra';\nimport globby from 'globby';\nimport { StaticAssetInput } from './types';\nimport { resolveSafeChildPath } from '@backstage/backend-common';\n\n/**\n * Finds all static assets within a directory\n *\n * @internal\n */\nexport async function findStaticAssets(\n staticDir: string,\n): Promise<StaticAssetInput[]> {\n const assetPaths = await globby('**/*', {\n ignore: ['**/*.map'], // Ignore source maps since they're quite large\n cwd: staticDir,\n dot: true,\n });\n\n return assetPaths.map(path => ({\n path,\n content: async () => fs.readFile(resolveSafeChildPath(staticDir, path)),\n }));\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport const CACHE_CONTROL_NO_CACHE = 'no-store, max-age=0';\nexport const CACHE_CONTROL_MAX_CACHE = 'public, max-age=1209600'; // 14 days\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { extname } from 'path';\nimport { RequestHandler } from 'express';\nimport { StaticAssetProvider } from './types';\nimport { CACHE_CONTROL_MAX_CACHE } from '../headers';\n\n/**\n * Creates a middleware that serves static assets from a static asset provider\n *\n * @internal\n */\nexport function createStaticAssetMiddleware(\n store: StaticAssetProvider,\n): RequestHandler {\n return (req, res, next) => {\n if (req.method !== 'GET' && req.method !== 'HEAD') {\n next();\n return;\n }\n\n // Let's not assume we're in promise-router\n Promise.resolve(\n (async () => {\n // Drop leading slashes from the incoming path\n const path = req.path.startsWith('/') ? req.path.slice(1) : req.path;\n\n const asset = await store.getAsset(path);\n if (!asset) {\n next();\n return;\n }\n\n // Set the Content-Type header, falling back to octet-stream\n const ext = extname(asset.path);\n if (ext) {\n res.type(ext);\n } else {\n res.type('bin');\n }\n\n // Same as our express.static override\n res.setHeader('Cache-Control', CACHE_CONTROL_MAX_CACHE);\n res.setHeader('Last-Modified', asset.lastModifiedAt.toUTCString());\n\n res.send(asset.content);\n })(),\n ).catch(next);\n };\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n notFoundHandler,\n PluginDatabaseManager,\n resolvePackagePath,\n} from '@backstage/backend-common';\nimport { Config } from '@backstage/config';\nimport helmet from 'helmet';\nimport express from 'express';\nimport Router from 'express-promise-router';\nimport fs from 'fs-extra';\nimport { resolve as resolvePath } from 'path';\nimport { Logger } from 'winston';\nimport { injectConfig, readConfigs } from '../lib/config';\nimport {\n StaticAssetsStore,\n findStaticAssets,\n createStaticAssetMiddleware,\n} from '../lib/assets';\nimport {\n CACHE_CONTROL_MAX_CACHE,\n CACHE_CONTROL_NO_CACHE,\n} from '../lib/headers';\n\n// express uses mime v1 while we only have types for mime v2\ntype Mime = { lookup(arg0: string): string };\n\n/** @public */\nexport interface RouterOptions {\n config: Config;\n logger: Logger;\n\n /**\n * If a database is provided it will be used to cache previously deployed static assets.\n *\n * This is a built-in alternative to using a `staticFallbackHandler`.\n */\n database?: PluginDatabaseManager;\n\n /**\n * The name of the app package that content should be served from. The same app package should be\n * added as a dependency to the backend package in order for it to be accessible at runtime.\n *\n * In a typical setup with a single app package this would be set to 'app'.\n */\n appPackageName: string;\n\n /**\n * A request handler to handle requests for static content that are not present in the app bundle.\n *\n * This can be used to avoid issues with clients on older deployment versions trying to access lazy\n * loaded content that is no longer present. Typically the requests would fall back to a long-term\n * object store where all recently deployed versions of the app are present.\n *\n * Another option is to provide a `database` that will take care of storing the static assets instead.\n *\n * If both `database` and `staticFallbackHandler` are provided, the `database` will attempt to serve\n * static assets first, and if they are not found, the `staticFallbackHandler` will be called.\n */\n staticFallbackHandler?: express.Handler;\n\n /**\n * Disables the configuration injection. This can be useful if you're running in an environment\n * with a read-only filesystem, or for some other reason don't want configuration to be injected.\n *\n * Note that this will cause the configuration used when building the app bundle to be used, unless\n * a separate configuration loading strategy is set up.\n *\n * This also disables configuration injection though `APP_CONFIG_` environment variables.\n */\n disableConfigInjection?: boolean;\n}\n\n/** @public */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const { config, logger, appPackageName, staticFallbackHandler } = options;\n\n const disableConfigInjection =\n options.disableConfigInjection ??\n config.getOptionalBoolean('app.disableConfigInjection');\n const disableStaticFallbackCache = config.getOptionalBoolean(\n 'app.disableStaticFallbackCache',\n );\n\n const appDistDir = resolvePackagePath(appPackageName, 'dist');\n const staticDir = resolvePath(appDistDir, 'static');\n\n if (!(await fs.pathExists(staticDir))) {\n if (process.env.NODE_ENV === 'production') {\n logger.error(\n `Can't serve static app content from ${staticDir}, directory doesn't exist`,\n );\n }\n\n return Router();\n }\n\n logger.info(`Serving static app content from ${appDistDir}`);\n\n if (!disableConfigInjection) {\n const appConfigs = await readConfigs({\n config,\n appDistDir,\n env: process.env,\n });\n\n await injectConfig({ appConfigs, logger, staticDir });\n }\n\n const router = Router();\n\n router.use(helmet.frameguard({ action: 'deny' }));\n\n // Use a separate router for static content so that a fallback can be provided by backend\n const staticRouter = Router();\n staticRouter.use(\n express.static(resolvePath(appDistDir, 'static'), {\n setHeaders: res => {\n res.setHeader('Cache-Control', CACHE_CONTROL_MAX_CACHE);\n },\n }),\n );\n\n if (options.database && !disableStaticFallbackCache) {\n const store = await StaticAssetsStore.create({\n logger,\n database: options.database,\n });\n\n const assets = await findStaticAssets(staticDir);\n await store.storeAssets(assets);\n // Remove any assets that are older than 7 days\n await store.trimAssets({ maxAgeSeconds: 60 * 60 * 24 * 7 });\n\n staticRouter.use(createStaticAssetMiddleware(store));\n }\n\n if (staticFallbackHandler) {\n staticRouter.use(staticFallbackHandler);\n }\n staticRouter.use(notFoundHandler());\n\n router.use('/static', staticRouter);\n router.use(\n express.static(appDistDir, {\n setHeaders: (res, path) => {\n // The Cache-Control header instructs the browser to not cache html files since it might\n // link to static assets from recently deployed versions.\n if (\n (express.static.mime as unknown as Mime).lookup(path) === 'text/html'\n ) {\n res.setHeader('Cache-Control', CACHE_CONTROL_NO_CACHE);\n }\n },\n }),\n );\n router.get('/*', (_req, res) => {\n res.sendFile(resolvePath(appDistDir, 'index.html'), {\n headers: {\n // The Cache-Control header instructs the browser to not cache the index.html since it might\n // link to static assets from recently deployed versions.\n 'cache-control': CACHE_CONTROL_NO_CACHE,\n },\n });\n });\n\n return router;\n}\n"],"names":["fs","path","resolvePath","readEnvConfig","loadConfigSchema","resolvePackagePath","partition","DateTime","globby","resolveSafeChildPath","extname","Router","helmet","express","notFoundHandler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiCA,eAAsB,aAAa,OAAwB,EAAA;AACzD,EAAA,MAAM,EAAE,SAAA,EAAW,MAAQ,EAAA,UAAA,EAAe,GAAA,OAAA,CAAA;AAE1C,EAAA,MAAM,KAAQ,GAAA,MAAMA,sBAAG,CAAA,OAAA,CAAQ,SAAS,CAAA,CAAA;AACxC,EAAA,MAAM,UAAU,KAAM,CAAA,MAAA,CAAO,UAAQ,IAAK,CAAA,QAAA,CAAS,KAAK,CAAC,CAAA,CAAA;AAEzD,EAAA,MAAM,cAAc,IAAK,CAAA,SAAA,CAAU,UAAU,CAAE,CAAA,OAAA,CAAQ,aAAa,MAAM,CAAA,CAAA;AAC1E,EAAM,MAAA,QAAA,GAAW,sCAAsC,WAAW,CAAA,qBAAA,CAAA,CAAA;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I,WAAW,YAAY,CAAA,CAAA;AAClC,EAAO,MAAA,CAAA,GAAA;AAAA,IACLD,2BAAA,CAAQ,OAAO,UAAY,EAAA;AAAA,MACzB,UAAA,EAAY,CAAC,GAAA,EAAK,IAAS,KAAA;AAGzB,QAAA,IACGA,4BAAQ,MAAO,CAAA,IAAA,CAAyB,MAAO,CAAA,IAAI,MAAM,WAC1D,EAAA;AACA,UAAI,GAAA,CAAA,SAAA,CAAU,iBAAiB,sBAAsB,CAAA,CAAA;AAAA,SACvD;AAAA,OACF;AAAA,KACD,CAAA;AAAA,GACH,CAAA;AACA,EAAA,MAAA,CAAO,GAAI,CAAA,IAAA,EAAM,CAAC,IAAA,EAAM,GAAQ,KAAA;AAC9B,IAAA,GAAA,CAAI,QAAS,CAAAX,YAAA,CAAY,UAAY,EAAA,YAAY,CAAG,EAAA;AAAA,MAClD,OAAS,EAAA;AAAA;AAAA;AAAA,QAGP,eAAiB,EAAA,sBAAA;AAAA,OACnB;AAAA,KACD,CAAA,CAAA;AAAA,GACF,CAAA,CAAA;AAED,EAAO,OAAA,MAAA,CAAA;AACT;;;;"}
package/dist/index.cjs.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var router = require('./cjs/router-78e92a6f.cjs.js');
5
+ var router = require('./cjs/router-62f9e896.cjs.js');
6
6
  require('@backstage/backend-common');
7
7
  require('helmet');
8
8
  require('express');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-app-backend",
3
3
  "description": "A Backstage backend plugin that serves the Backstage frontend app",
4
- "version": "0.3.48-next.1",
4
+ "version": "0.3.48-next.2",
5
5
  "main": "./dist/index.cjs.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "license": "Apache-2.0",
@@ -43,10 +43,11 @@
43
43
  "clean": "backstage-cli package clean"
44
44
  },
45
45
  "dependencies": {
46
- "@backstage/backend-common": "^0.19.2-next.1",
47
- "@backstage/backend-plugin-api": "^0.6.0-next.1",
46
+ "@backstage/backend-common": "^0.19.2-next.2",
47
+ "@backstage/backend-plugin-api": "^0.6.0-next.2",
48
48
  "@backstage/config": "^1.0.8",
49
49
  "@backstage/config-loader": "^1.4.0-next.1",
50
+ "@backstage/plugin-app-node": "^0.1.0-next.0",
50
51
  "@backstage/types": "^1.1.0",
51
52
  "@types/express": "^4.17.6",
52
53
  "express": "^4.17.1",
@@ -61,8 +62,8 @@
61
62
  "yn": "^4.0.0"
62
63
  },
63
64
  "devDependencies": {
64
- "@backstage/backend-app-api": "^0.5.0-next.1",
65
- "@backstage/backend-test-utils": "^0.2.0-next.1",
65
+ "@backstage/backend-app-api": "^0.5.0-next.2",
66
+ "@backstage/backend-test-utils": "^0.2.0-next.2",
66
67
  "@backstage/cli": "^0.22.10-next.1",
67
68
  "@backstage/types": "^1.1.0",
68
69
  "@types/supertest": "^2.0.8",
@@ -71,8 +72,10 @@
71
72
  "node-fetch": "^2.6.7",
72
73
  "supertest": "^6.1.3"
73
74
  },
75
+ "configSchema": "config.d.ts",
74
76
  "files": [
75
77
  "dist",
78
+ "config.d.ts",
76
79
  "migrations/**/*.{js,d.ts}",
77
80
  "static",
78
81
  "alpha"