@backstage/plugin-app-backend 0.5.10 → 0.5.11-next.0

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,19 @@
1
1
  # @backstage/plugin-app-backend
2
2
 
3
+ ## 0.5.11-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 7455dae: Use node prefix on native imports
8
+ - Updated dependencies
9
+ - @backstage/backend-plugin-api@1.7.0-next.0
10
+ - @backstage/config-loader@1.10.8-next.0
11
+ - @backstage/plugin-auth-node@0.6.12-next.0
12
+ - @backstage/plugin-app-node@0.1.42-next.0
13
+ - @backstage/config@1.3.6
14
+ - @backstage/errors@1.2.7
15
+ - @backstage/types@1.2.2
16
+
3
17
  ## 0.5.10
4
18
 
5
19
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var path = require('path');
3
+ var node_path = require('node:path');
4
4
  var headers = require('../headers.cjs.js');
5
5
 
6
6
  function createStaticAssetMiddleware(store) {
@@ -11,13 +11,13 @@ function createStaticAssetMiddleware(store) {
11
11
  }
12
12
  Promise.resolve(
13
13
  (async () => {
14
- const path$1 = req.path.startsWith("/") ? req.path.slice(1) : req.path;
15
- const asset = await store.getAsset(path$1);
14
+ const path = req.path.startsWith("/") ? req.path.slice(1) : req.path;
15
+ const asset = await store.getAsset(path);
16
16
  if (!asset) {
17
17
  next();
18
18
  return;
19
19
  }
20
- const ext = path.extname(asset.path);
20
+ const ext = node_path.extname(asset.path);
21
21
  if (ext) {
22
22
  res.type(ext);
23
23
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"createStaticAssetMiddleware.cjs.js","sources":["../../../src/lib/assets/createStaticAssetMiddleware.ts"],"sourcesContent":["/*\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"],"names":["path","extname","CACHE_CONTROL_MAX_CACHE"],"mappings":";;;;;AA0BO,SAAS,4BACd,KAAA,EACgB;AAChB,EAAA,OAAO,CAAC,GAAA,EAAK,GAAA,EAAK,IAAA,KAAS;AACzB,IAAA,IAAI,GAAA,CAAI,MAAA,KAAW,KAAA,IAAS,GAAA,CAAI,WAAW,MAAA,EAAQ;AACjD,MAAA,IAAA,EAAK;AACL,MAAA;AAAA,IACF;AAGA,IAAA,OAAA,CAAQ,OAAA;AAAA,MAAA,CACL,YAAY;AAEX,QAAA,MAAMA,MAAA,GAAO,GAAA,CAAI,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,GAAI,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,GAAI,GAAA,CAAI,IAAA;AAEhE,QAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,CAAM,QAAA,CAASA,MAAI,CAAA;AACvC,QAAA,IAAI,CAAC,KAAA,EAAO;AACV,UAAA,IAAA,EAAK;AACL,UAAA;AAAA,QACF;AAGA,QAAA,MAAM,GAAA,GAAMC,YAAA,CAAQ,KAAA,CAAM,IAAI,CAAA;AAC9B,QAAA,IAAI,GAAA,EAAK;AACP,UAAA,GAAA,CAAI,KAAK,GAAG,CAAA;AAAA,QACd,CAAA,MAAO;AACL,UAAA,GAAA,CAAI,KAAK,KAAK,CAAA;AAAA,QAChB;AAGA,QAAA,GAAA,CAAI,SAAA,CAAU,iBAAiBC,+BAAuB,CAAA;AACtD,QAAA,GAAA,CAAI,SAAA,CAAU,eAAA,EAAiB,KAAA,CAAM,cAAA,CAAe,aAAa,CAAA;AAEjE,QAAA,GAAA,CAAI,IAAA,CAAK,MAAM,OAAO,CAAA;AAAA,MACxB,CAAA;AAAG,KACL,CAAE,MAAM,IAAI,CAAA;AAAA,EACd,CAAA;AACF;;;;"}
1
+ {"version":3,"file":"createStaticAssetMiddleware.cjs.js","sources":["../../../src/lib/assets/createStaticAssetMiddleware.ts"],"sourcesContent":["/*\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 'node: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"],"names":["extname","CACHE_CONTROL_MAX_CACHE"],"mappings":";;;;;AA0BO,SAAS,4BACd,KAAA,EACgB;AAChB,EAAA,OAAO,CAAC,GAAA,EAAK,GAAA,EAAK,IAAA,KAAS;AACzB,IAAA,IAAI,GAAA,CAAI,MAAA,KAAW,KAAA,IAAS,GAAA,CAAI,WAAW,MAAA,EAAQ;AACjD,MAAA,IAAA,EAAK;AACL,MAAA;AAAA,IACF;AAGA,IAAA,OAAA,CAAQ,OAAA;AAAA,MAAA,CACL,YAAY;AAEX,QAAA,MAAM,IAAA,GAAO,GAAA,CAAI,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,GAAI,GAAA,CAAI,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,GAAI,GAAA,CAAI,IAAA;AAEhE,QAAA,MAAM,KAAA,GAAQ,MAAM,KAAA,CAAM,QAAA,CAAS,IAAI,CAAA;AACvC,QAAA,IAAI,CAAC,KAAA,EAAO;AACV,UAAA,IAAA,EAAK;AACL,UAAA;AAAA,QACF;AAGA,QAAA,MAAM,GAAA,GAAMA,iBAAA,CAAQ,KAAA,CAAM,IAAI,CAAA;AAC9B,QAAA,IAAI,GAAA,EAAK;AACP,UAAA,GAAA,CAAI,KAAK,GAAG,CAAA;AAAA,QACd,CAAA,MAAO;AACL,UAAA,GAAA,CAAI,KAAK,KAAK,CAAA;AAAA,QAChB;AAGA,QAAA,GAAA,CAAI,SAAA,CAAU,iBAAiBC,+BAAuB,CAAA;AACtD,QAAA,GAAA,CAAI,SAAA,CAAU,eAAA,EAAiB,KAAA,CAAM,cAAA,CAAe,aAAa,CAAA;AAEjE,QAAA,GAAA,CAAI,IAAA,CAAK,MAAM,OAAO,CAAA;AAAA,MACxB,CAAA;AAAG,KACL,CAAE,MAAM,IAAI,CAAA;AAAA,EACd,CAAA;AACF;;;;"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var fs = require('fs-extra');
4
- var path = require('path');
4
+ var node_path = require('node:path');
5
5
  var compileTemplate = require('lodash/template');
6
6
  var config = require('@backstage/config');
7
7
 
@@ -13,12 +13,12 @@ var compileTemplate__default = /*#__PURE__*/_interopDefaultCompat(compileTemplat
13
13
  const HTML_TEMPLATE_NAME = "index.html.tmpl";
14
14
  async function injectConfigIntoHtml(options) {
15
15
  const { rootDir, appConfigs } = options;
16
- const templatePath = path.resolve(rootDir, HTML_TEMPLATE_NAME);
16
+ const templatePath = node_path.resolve(rootDir, HTML_TEMPLATE_NAME);
17
17
  if (!await fs__default.default.exists(templatePath)) {
18
18
  return void 0;
19
19
  }
20
20
  const templateContent = await fs__default.default.readFile(
21
- path.resolve(rootDir, HTML_TEMPLATE_NAME),
21
+ node_path.resolve(rootDir, HTML_TEMPLATE_NAME),
22
22
  "utf8"
23
23
  );
24
24
  const config$1 = config.ConfigReader.fromConfigs(appConfigs);
@@ -1 +1 @@
1
- {"version":3,"file":"injectConfigIntoHtml.cjs.js","sources":["../../../src/lib/config/injectConfigIntoHtml.ts"],"sourcesContent":["/*\n * Copyright 2024 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 { InjectOptions } from './types';\nimport compileTemplate from 'lodash/template';\nimport { Config, ConfigReader } from '@backstage/config';\n\nconst HTML_TEMPLATE_NAME = 'index.html.tmpl';\n\n/** @internal */\nexport async function injectConfigIntoHtml(\n options: InjectOptions,\n): Promise<Buffer | undefined> {\n const { rootDir, appConfigs } = options;\n\n const templatePath = resolvePath(rootDir, HTML_TEMPLATE_NAME);\n\n if (!(await fs.exists(templatePath))) {\n return undefined;\n }\n\n const templateContent = await fs.readFile(\n resolvePath(rootDir, HTML_TEMPLATE_NAME),\n 'utf8',\n );\n\n const config = ConfigReader.fromConfigs(appConfigs);\n\n const templateSource = compileTemplate(templateContent, {\n interpolate: /<%=([\\s\\S]+?)%>/g,\n });\n\n const publicPath = resolvePublicPath(config);\n const indexHtmlContent = templateSource({\n config,\n publicPath,\n });\n\n const indexHtmlContentWithConfig = indexHtmlContent.replace(\n '</head>',\n `\n<script type=\"backstage.io/config\">\n${JSON.stringify(appConfigs, null, 2)\n // Note on the security aspects of this: We generally trust the app config to\n // be safe, since control of the app config effectively means full control of\n // the app. These substitutions are here as an extra precaution to avoid\n // unintentionally breaking the app, to avoid this being flagged, and in case\n // someone decides to hook up user input to the app config in their own setup.\n .replaceAll('</script', '')\n .replaceAll('<!--', '')}\n</script>\n</head>`,\n );\n\n return Buffer.from(indexHtmlContentWithConfig, 'utf8');\n}\n\nexport function resolvePublicPath(config: Config) {\n const baseUrl = new URL(\n config.getOptionalString('app.baseUrl') ?? '/',\n 'http://localhost:7007',\n );\n return baseUrl.pathname.replace(/\\/+$/, '');\n}\n"],"names":["resolvePath","fs","config","ConfigReader","compileTemplate"],"mappings":";;;;;;;;;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C;AAAA,GACF;AACA,EAAA,OAAO,OAAA,CAAQ,QAAA,CAAS,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AAC5C;;;;;"}
1
+ {"version":3,"file":"injectConfigIntoHtml.cjs.js","sources":["../../../src/lib/config/injectConfigIntoHtml.ts"],"sourcesContent":["/*\n * Copyright 2024 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 'node:path';\nimport { InjectOptions } from './types';\nimport compileTemplate from 'lodash/template';\nimport { Config, ConfigReader } from '@backstage/config';\n\nconst HTML_TEMPLATE_NAME = 'index.html.tmpl';\n\n/** @internal */\nexport async function injectConfigIntoHtml(\n options: InjectOptions,\n): Promise<Buffer | undefined> {\n const { rootDir, appConfigs } = options;\n\n const templatePath = resolvePath(rootDir, HTML_TEMPLATE_NAME);\n\n if (!(await fs.exists(templatePath))) {\n return undefined;\n }\n\n const templateContent = await fs.readFile(\n resolvePath(rootDir, HTML_TEMPLATE_NAME),\n 'utf8',\n );\n\n const config = ConfigReader.fromConfigs(appConfigs);\n\n const templateSource = compileTemplate(templateContent, {\n interpolate: /<%=([\\s\\S]+?)%>/g,\n });\n\n const publicPath = resolvePublicPath(config);\n const indexHtmlContent = templateSource({\n config,\n publicPath,\n });\n\n const indexHtmlContentWithConfig = indexHtmlContent.replace(\n '</head>',\n `\n<script type=\"backstage.io/config\">\n${JSON.stringify(appConfigs, null, 2)\n // Note on the security aspects of this: We generally trust the app config to\n // be safe, since control of the app config effectively means full control of\n // the app. These substitutions are here as an extra precaution to avoid\n // unintentionally breaking the app, to avoid this being flagged, and in case\n // someone decides to hook up user input to the app config in their own setup.\n .replaceAll('</script', '')\n .replaceAll('<!--', '')}\n</script>\n</head>`,\n );\n\n return Buffer.from(indexHtmlContentWithConfig, 'utf8');\n}\n\nexport function resolvePublicPath(config: Config) {\n const baseUrl = new URL(\n config.getOptionalString('app.baseUrl') ?? '/',\n 'http://localhost:7007',\n );\n return baseUrl.pathname.replace(/\\/+$/, '');\n}\n"],"names":["resolvePath","fs","config","ConfigReader","compileTemplate"],"mappings":";;;;;;;;;;;;AAsBA,MAAM,kBAAA,GAAqB,iBAAA;AAG3B,eAAsB,qBACpB,OAAA,EAC6B;AAC7B,EAAA,MAAM,EAAE,OAAA,EAAS,UAAA,EAAW,GAAI,OAAA;AAEhC,EAAA,MAAM,YAAA,GAAeA,iBAAA,CAAY,OAAA,EAAS,kBAAkB,CAAA;AAE5D,EAAA,IAAI,CAAE,MAAMC,mBAAA,CAAG,MAAA,CAAO,YAAY,CAAA,EAAI;AACpC,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,MAAM,eAAA,GAAkB,MAAMA,mBAAA,CAAG,QAAA;AAAA,IAC/BD,iBAAA,CAAY,SAAS,kBAAkB,CAAA;AAAA,IACvC;AAAA,GACF;AAEA,EAAA,MAAME,QAAA,GAASC,mBAAA,CAAa,WAAA,CAAY,UAAU,CAAA;AAElD,EAAA,MAAM,cAAA,GAAiBC,iCAAgB,eAAA,EAAiB;AAAA,IACtD,WAAA,EAAa;AAAA,GACd,CAAA;AAED,EAAA,MAAM,UAAA,GAAa,kBAAkBF,QAAM,CAAA;AAC3C,EAAA,MAAM,mBAAmB,cAAA,CAAe;AAAA,YACtCA,QAAA;AAAA,IACA;AAAA,GACD,CAAA;AAED,EAAA,MAAM,6BAA6B,gBAAA,CAAiB,OAAA;AAAA,IAClD,SAAA;AAAA,IACA;AAAA;AAAA,EAEF,IAAA,CAAK,SAAA,CAAU,UAAA,EAAY,IAAA,EAAM,CAAC,CAAA,CAMjC,UAAA,CAAW,WAAA,EAAY,EAAE,CAAA,CACzB,UAAA,CAAW,MAAA,EAAQ,EAAE,CAAC;AAAA;AAAA,OAAA;AAAA,GAGvB;AAEA,EAAA,OAAO,MAAA,CAAO,IAAA,CAAK,0BAAA,EAA4B,MAAM,CAAA;AACvD;AAEO,SAAS,kBAAkB,MAAA,EAAgB;AAChD,EAAA,MAAM,UAAU,IAAI,GAAA;AAAA,IAClB,MAAA,CAAO,iBAAA,CAAkB,aAAa,CAAA,IAAK,GAAA;AAAA,IAC3C;AAAA,GACF;AACA,EAAA,OAAO,OAAA,CAAQ,QAAA,CAAS,OAAA,CAAQ,MAAA,EAAQ,EAAE,CAAA;AAC5C;;;;;"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var fs = require('fs-extra');
4
- var path = require('path');
4
+ var node_path = require('node:path');
5
5
 
6
6
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
7
7
 
@@ -14,24 +14,24 @@ async function injectConfigIntoStatic(options) {
14
14
  const escapedData = JSON.stringify(appConfigs).replace(/("|'|\\)/g, "\\$1");
15
15
  const injected = `/*__APP_INJECTED_CONFIG_MARKER__*/"${escapedData}"/*__INJECTED_END__*/`;
16
16
  for (const jsFile of jsFiles) {
17
- const path$1 = path.resolve(staticDir, jsFile);
18
- const content = await fs__default.default.readFile(path$1, "utf8");
17
+ const path = node_path.resolve(staticDir, jsFile);
18
+ const content = await fs__default.default.readFile(path, "utf8");
19
19
  if (content.includes("__APP_INJECTED_RUNTIME_CONFIG__")) {
20
20
  logger.info(`Injecting env config into ${jsFile}`);
21
21
  const newContent = content.replaceAll(
22
22
  '"__APP_INJECTED_RUNTIME_CONFIG__"',
23
23
  injected
24
24
  );
25
- await fs__default.default.writeFile(path$1, newContent, "utf8");
26
- return path$1;
25
+ await fs__default.default.writeFile(path, newContent, "utf8");
26
+ return path;
27
27
  } else if (content.includes("__APP_INJECTED_CONFIG_MARKER__")) {
28
28
  logger.info(`Replacing injected env config in ${jsFile}`);
29
29
  const newContent = content.replaceAll(
30
30
  /\/\*__APP_INJECTED_CONFIG_MARKER__\*\/.*?\/\*__INJECTED_END__\*\//g,
31
31
  injected
32
32
  );
33
- await fs__default.default.writeFile(path$1, newContent, "utf8");
34
- return path$1;
33
+ await fs__default.default.writeFile(path, newContent, "utf8");
34
+ return path;
35
35
  }
36
36
  }
37
37
  logger.info("Env config not injected");
@@ -1 +1 @@
1
- {"version":3,"file":"injectConfigIntoStatic.cjs.js","sources":["../../../src/lib/config/injectConfigIntoStatic.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 { InjectOptions } from './types';\n\n/**\n * Injects configs into the app bundle, replacing any existing injected config.\n */\nexport async function injectConfigIntoStatic(\n options: InjectOptions,\n): Promise<string | undefined> {\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.replaceAll(\n '\"__APP_INJECTED_RUNTIME_CONFIG__\"',\n injected,\n );\n await fs.writeFile(path, newContent, 'utf8');\n return path;\n } else if (content.includes('__APP_INJECTED_CONFIG_MARKER__')) {\n logger.info(`Replacing injected env config in ${jsFile}`);\n\n const newContent = content.replaceAll(\n /\\/\\*__APP_INJECTED_CONFIG_MARKER__\\*\\/.*?\\/\\*__INJECTED_END__\\*\\//g,\n injected,\n );\n await fs.writeFile(path, newContent, 'utf8');\n return path;\n }\n }\n logger.info('Env config not injected');\n return undefined;\n}\n"],"names":["fs","path","resolvePath"],"mappings":";;;;;;;;;AAuBA,eAAsB,uBACpB,OAAA,EAC6B;AAC7B,EAAA,MAAM,EAAE,SAAA,EAAW,MAAA,EAAQ,UAAA,EAAW,GAAI,OAAA;AAE1C,EAAA,MAAM,KAAA,GAAQ,MAAMA,mBAAA,CAAG,OAAA,CAAQ,SAAS,CAAA;AACxC,EAAA,MAAM,UAAU,KAAA,CAAM,MAAA,CAAO,UAAQ,IAAA,CAAK,QAAA,CAAS,KAAK,CAAC,CAAA;AAEzD,EAAA,MAAM,cAAc,IAAA,CAAK,SAAA,CAAU,UAAU,CAAA,CAAE,OAAA,CAAQ,aAAa,MAAM,CAAA;AAC1E,EAAA,MAAM,QAAA,GAAW,sCAAsC,WAAW,CAAA,qBAAA,CAAA;AAElE,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,IAAA,MAAMC,MAAA,GAAOC,YAAA,CAAY,SAAA,EAAW,MAAM,CAAA;AAE1C,IAAA,MAAM,OAAA,GAAU,MAAMF,mBAAA,CAAG,QAAA,CAASC,QAAM,MAAM,CAAA;AAC9C,IAAA,IAAI,OAAA,CAAQ,QAAA,CAAS,iCAAiC,CAAA,EAAG;AACvD,MAAA,MAAA,CAAO,IAAA,CAAK,CAAA,0BAAA,EAA6B,MAAM,CAAA,CAAE,CAAA;AAEjD,MAAA,MAAM,aAAa,OAAA,CAAQ,UAAA;AAAA,QACzB,mCAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,MAAMD,mBAAA,CAAG,SAAA,CAAUC,MAAA,EAAM,UAAA,EAAY,MAAM,CAAA;AAC3C,MAAA,OAAOA,MAAA;AAAA,IACT,CAAA,MAAA,IAAW,OAAA,CAAQ,QAAA,CAAS,gCAAgC,CAAA,EAAG;AAC7D,MAAA,MAAA,CAAO,IAAA,CAAK,CAAA,iCAAA,EAAoC,MAAM,CAAA,CAAE,CAAA;AAExD,MAAA,MAAM,aAAa,OAAA,CAAQ,UAAA;AAAA,QACzB,oEAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,MAAMD,mBAAA,CAAG,SAAA,CAAUC,MAAA,EAAM,UAAA,EAAY,MAAM,CAAA;AAC3C,MAAA,OAAOA,MAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,MAAA,CAAO,KAAK,yBAAyB,CAAA;AACrC,EAAA,OAAO,MAAA;AACT;;;;"}
1
+ {"version":3,"file":"injectConfigIntoStatic.cjs.js","sources":["../../../src/lib/config/injectConfigIntoStatic.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 'node:path';\nimport { InjectOptions } from './types';\n\n/**\n * Injects configs into the app bundle, replacing any existing injected config.\n */\nexport async function injectConfigIntoStatic(\n options: InjectOptions,\n): Promise<string | undefined> {\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.replaceAll(\n '\"__APP_INJECTED_RUNTIME_CONFIG__\"',\n injected,\n );\n await fs.writeFile(path, newContent, 'utf8');\n return path;\n } else if (content.includes('__APP_INJECTED_CONFIG_MARKER__')) {\n logger.info(`Replacing injected env config in ${jsFile}`);\n\n const newContent = content.replaceAll(\n /\\/\\*__APP_INJECTED_CONFIG_MARKER__\\*\\/.*?\\/\\*__INJECTED_END__\\*\\//g,\n injected,\n );\n await fs.writeFile(path, newContent, 'utf8');\n return path;\n }\n }\n logger.info('Env config not injected');\n return undefined;\n}\n"],"names":["fs","resolvePath"],"mappings":";;;;;;;;;AAuBA,eAAsB,uBACpB,OAAA,EAC6B;AAC7B,EAAA,MAAM,EAAE,SAAA,EAAW,MAAA,EAAQ,UAAA,EAAW,GAAI,OAAA;AAE1C,EAAA,MAAM,KAAA,GAAQ,MAAMA,mBAAA,CAAG,OAAA,CAAQ,SAAS,CAAA;AACxC,EAAA,MAAM,UAAU,KAAA,CAAM,MAAA,CAAO,UAAQ,IAAA,CAAK,QAAA,CAAS,KAAK,CAAC,CAAA;AAEzD,EAAA,MAAM,cAAc,IAAA,CAAK,SAAA,CAAU,UAAU,CAAA,CAAE,OAAA,CAAQ,aAAa,MAAM,CAAA;AAC1E,EAAA,MAAM,QAAA,GAAW,sCAAsC,WAAW,CAAA,qBAAA,CAAA;AAElE,EAAA,KAAA,MAAW,UAAU,OAAA,EAAS;AAC5B,IAAA,MAAM,IAAA,GAAOC,iBAAA,CAAY,SAAA,EAAW,MAAM,CAAA;AAE1C,IAAA,MAAM,OAAA,GAAU,MAAMD,mBAAA,CAAG,QAAA,CAAS,MAAM,MAAM,CAAA;AAC9C,IAAA,IAAI,OAAA,CAAQ,QAAA,CAAS,iCAAiC,CAAA,EAAG;AACvD,MAAA,MAAA,CAAO,IAAA,CAAK,CAAA,0BAAA,EAA6B,MAAM,CAAA,CAAE,CAAA;AAEjD,MAAA,MAAM,aAAa,OAAA,CAAQ,UAAA;AAAA,QACzB,mCAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,MAAMA,mBAAA,CAAG,SAAA,CAAU,IAAA,EAAM,UAAA,EAAY,MAAM,CAAA;AAC3C,MAAA,OAAO,IAAA;AAAA,IACT,CAAA,MAAA,IAAW,OAAA,CAAQ,QAAA,CAAS,gCAAgC,CAAA,EAAG;AAC7D,MAAA,MAAA,CAAO,IAAA,CAAK,CAAA,iCAAA,EAAoC,MAAM,CAAA,CAAE,CAAA;AAExD,MAAA,MAAM,aAAa,OAAA,CAAQ,UAAA;AAAA,QACzB,oEAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA,MAAMA,mBAAA,CAAG,SAAA,CAAU,IAAA,EAAM,UAAA,EAAY,MAAM,CAAA;AAC3C,MAAA,OAAO,IAAA;AAAA,IACT;AAAA,EACF;AACA,EAAA,MAAA,CAAO,KAAK,yBAAyB,CAAA;AACrC,EAAA,OAAO,MAAA;AACT;;;;"}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var fs = require('fs-extra');
4
- var path = require('path');
4
+ var node_path = require('node:path');
5
5
  var configLoader = require('@backstage/config-loader');
6
6
 
7
7
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
@@ -10,7 +10,7 @@ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
10
10
 
11
11
  async function readFrontendConfig(options) {
12
12
  const { env, appDistDir, config } = options;
13
- const schemaPath = path.resolve(appDistDir, ".config-schema.json");
13
+ const schemaPath = node_path.resolve(appDistDir, ".config-schema.json");
14
14
  if (await fs__default.default.pathExists(schemaPath)) {
15
15
  const envConfigs = configLoader.readEnvConfig(env);
16
16
  const serializedSchema = await fs__default.default.readJson(schemaPath);
@@ -1 +1 @@
1
- {"version":3,"file":"readFrontendConfig.cjs.js","sources":["../../../src/lib/config/readFrontendConfig.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 { AppConfig, Config } from '@backstage/config';\nimport { JsonObject } from '@backstage/types';\nimport {\n ConfigSchema,\n loadConfigSchema,\n readEnvConfig,\n} from '@backstage/config-loader';\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 readFrontendConfig(options: {\n env: { [name: string]: string | undefined };\n appDistDir: string;\n config: Config;\n schema?: ConfigSchema;\n}): Promise<AppConfig[]> {\n const { env, appDistDir, config } = options;\n\n const schemaPath = resolvePath(appDistDir, '.config-schema.json');\n if (await fs.pathExists(schemaPath)) {\n const envConfigs = readEnvConfig(env);\n const serializedSchema = await fs.readJson(schemaPath);\n\n try {\n const schema =\n options.schema ||\n (await loadConfigSchema({\n serialized: serializedSchema,\n }));\n\n return await schema.process(\n [...envConfigs, { data: config.get() as JsonObject, context: 'app' }],\n { visibility: ['frontend'], withDeprecatedKeys: true },\n );\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 [];\n}\n"],"names":["resolvePath","fs","readEnvConfig","loadConfigSchema"],"mappings":";;;;;;;;;;AA8BA,eAAsB,mBAAmB,OAAA,EAKhB;AACvB,EAAA,MAAM,EAAE,GAAA,EAAK,UAAA,EAAY,MAAA,EAAO,GAAI,OAAA;AAEpC,EAAA,MAAM,UAAA,GAAaA,YAAA,CAAY,UAAA,EAAY,qBAAqB,CAAA;AAChE,EAAA,IAAI,MAAMC,mBAAA,CAAG,UAAA,CAAW,UAAU,CAAA,EAAG;AACnC,IAAA,MAAM,UAAA,GAAaC,2BAAc,GAAG,CAAA;AACpC,IAAA,MAAM,gBAAA,GAAmB,MAAMD,mBAAA,CAAG,QAAA,CAAS,UAAU,CAAA;AAErD,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,GACJ,OAAA,CAAQ,MAAA,IACP,MAAME,6BAAA,CAAiB;AAAA,QACtB,UAAA,EAAY;AAAA,OACb,CAAA;AAEH,MAAA,OAAO,MAAM,MAAA,CAAO,OAAA;AAAA,QAClB,CAAC,GAAG,UAAA,EAAY,EAAE,IAAA,EAAM,OAAO,GAAA,EAAI,EAAiB,OAAA,EAAS,KAAA,EAAO,CAAA;AAAA,QACpE,EAAE,UAAA,EAAY,CAAC,UAAU,CAAA,EAAG,oBAAoB,IAAA;AAAK,OACvD;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,qPAE2C,KAAK,CAAA;AAAA,OAClD;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,EAAC;AACV;;;;"}
1
+ {"version":3,"file":"readFrontendConfig.cjs.js","sources":["../../../src/lib/config/readFrontendConfig.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 'node:path';\nimport { AppConfig, Config } from '@backstage/config';\nimport { JsonObject } from '@backstage/types';\nimport {\n ConfigSchema,\n loadConfigSchema,\n readEnvConfig,\n} from '@backstage/config-loader';\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 readFrontendConfig(options: {\n env: { [name: string]: string | undefined };\n appDistDir: string;\n config: Config;\n schema?: ConfigSchema;\n}): Promise<AppConfig[]> {\n const { env, appDistDir, config } = options;\n\n const schemaPath = resolvePath(appDistDir, '.config-schema.json');\n if (await fs.pathExists(schemaPath)) {\n const envConfigs = readEnvConfig(env);\n const serializedSchema = await fs.readJson(schemaPath);\n\n try {\n const schema =\n options.schema ||\n (await loadConfigSchema({\n serialized: serializedSchema,\n }));\n\n return await schema.process(\n [...envConfigs, { data: config.get() as JsonObject, context: 'app' }],\n { visibility: ['frontend'], withDeprecatedKeys: true },\n );\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 [];\n}\n"],"names":["resolvePath","fs","readEnvConfig","loadConfigSchema"],"mappings":";;;;;;;;;;AA8BA,eAAsB,mBAAmB,OAAA,EAKhB;AACvB,EAAA,MAAM,EAAE,GAAA,EAAK,UAAA,EAAY,MAAA,EAAO,GAAI,OAAA;AAEpC,EAAA,MAAM,UAAA,GAAaA,iBAAA,CAAY,UAAA,EAAY,qBAAqB,CAAA;AAChE,EAAA,IAAI,MAAMC,mBAAA,CAAG,UAAA,CAAW,UAAU,CAAA,EAAG;AACnC,IAAA,MAAM,UAAA,GAAaC,2BAAc,GAAG,CAAA;AACpC,IAAA,MAAM,gBAAA,GAAmB,MAAMD,mBAAA,CAAG,QAAA,CAAS,UAAU,CAAA;AAErD,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,GACJ,OAAA,CAAQ,MAAA,IACP,MAAME,6BAAA,CAAiB;AAAA,QACtB,UAAA,EAAY;AAAA,OACb,CAAA;AAEH,MAAA,OAAO,MAAM,MAAA,CAAO,OAAA;AAAA,QAClB,CAAC,GAAG,UAAA,EAAY,EAAE,IAAA,EAAM,OAAO,GAAA,EAAI,EAAiB,OAAA,EAAS,KAAA,EAAO,CAAA;AAAA,QACpE,EAAE,UAAA,EAAY,CAAC,UAAU,CAAA,EAAG,oBAAoB,IAAA;AAAK,OACvD;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,qPAE2C,KAAK,CAAA;AAAA,OAClD;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,EAAC;AACV;;;;"}
@@ -5,7 +5,7 @@ var helmet = require('helmet');
5
5
  var express = require('express');
6
6
  var Router = require('express-promise-router');
7
7
  var fs = require('fs-extra');
8
- var path = require('path');
8
+ var node_path = require('node:path');
9
9
  var StaticAssetsStore = require('../lib/assets/StaticAssetsStore.cjs.js');
10
10
  var findStaticAssets = require('../lib/assets/findStaticAssets.cjs.js');
11
11
  var createStaticAssetMiddleware = require('../lib/assets/createStaticAssetMiddleware.cjs.js');
@@ -38,7 +38,7 @@ async function createRouter(options) {
38
38
  "app.disableStaticFallbackCache"
39
39
  );
40
40
  const appDistDir = backendPluginApi.resolvePackagePath(appPackageName, "dist");
41
- const staticDir = path.resolve(appDistDir, "static");
41
+ const staticDir = node_path.resolve(appDistDir, "static");
42
42
  if (!await fs__default.default.pathExists(staticDir)) {
43
43
  if (process.env.NODE_ENV === "production") {
44
44
  logger.error(
@@ -60,7 +60,7 @@ async function createRouter(options) {
60
60
  }) : void 0;
61
61
  const router = Router__default.default();
62
62
  router.use(helmet__default.default.frameguard({ action: "deny" }));
63
- const publicDistDir = path.resolve(appDistDir, "public");
63
+ const publicDistDir = node_path.resolve(appDistDir, "public");
64
64
  const enablePublicEntryPoint = await fs__default.default.pathExists(publicDistDir);
65
65
  if (enablePublicEntryPoint) {
66
66
  logger.info(
@@ -135,7 +135,7 @@ async function createEntryPointRouter({
135
135
  staticFallbackHandler,
136
136
  appConfigs
137
137
  }) {
138
- const staticDir = path.resolve(rootDir, "static");
138
+ const staticDir = node_path.resolve(rootDir, "static");
139
139
  const injectResult = appConfigs && await injectConfig.injectConfig({ appConfigs, logger, rootDir, staticDir });
140
140
  const router = Router__default.default();
141
141
  const staticRouter = Router__default.default();
@@ -187,7 +187,7 @@ async function createEntryPointRouter({
187
187
  res.setHeader("Cache-Control", headers.CACHE_CONTROL_NO_CACHE);
188
188
  res.send(injectResult.indexHtmlContent);
189
189
  } else {
190
- res.sendFile(path.resolve(rootDir, "index.html"), {
190
+ res.sendFile(node_path.resolve(rootDir, "index.html"), {
191
191
  headers: {
192
192
  // The Cache-Control header instructs the browser to not cache the index.html since it might
193
193
  // link to static assets from recently deployed versions.
@@ -1 +1 @@
1
- {"version":3,"file":"router.cjs.js","sources":["../../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 {\n DatabaseService,\n resolvePackagePath,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport type { AppConfig } from '@backstage/config';\nimport helmet from 'helmet';\nimport express, { Request, Response } from 'express';\nimport Router from 'express-promise-router';\nimport fs from 'fs-extra';\nimport { resolve as resolvePath } from 'path';\nimport {\n createStaticAssetMiddleware,\n findStaticAssets,\n StaticAssetsStore,\n} from '../lib/assets';\nimport {\n CACHE_CONTROL_MAX_CACHE,\n CACHE_CONTROL_NO_CACHE,\n CACHE_CONTROL_REVALIDATE_CACHE,\n} from '../lib/headers';\nimport type { ConfigSchema } from '@backstage/config-loader';\nimport {\n AuthService,\n HttpAuthService,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport { AuthenticationError, InputError } from '@backstage/errors';\nimport { injectConfig, readFrontendConfig } from '../lib/config';\n\n// express uses mime v1 while we only have types for mime v2\ntype Mime = { lookup(arg0: string): string };\n\n/**\n * @internal\n */\nexport interface RouterOptions {\n config: RootConfigService;\n logger: LoggerService;\n auth: AuthService;\n httpAuth: HttpAuthService;\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: DatabaseService;\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 *\n * Provides a ConfigSchema.\n *\n */\n schema?: ConfigSchema;\n}\n\n/**\n * @internal\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const {\n config,\n logger,\n appPackageName,\n staticFallbackHandler,\n auth,\n httpAuth,\n schema,\n } = options;\n\n const disableConfigInjection = config.getOptionalBoolean(\n 'app.disableConfigInjection',\n );\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 const appConfigs = disableConfigInjection\n ? undefined\n : await readFrontendConfig({\n config,\n appDistDir,\n env: process.env,\n schema,\n });\n\n const assetStore = !disableStaticFallbackCache\n ? await StaticAssetsStore.create({\n logger,\n database: options.database,\n })\n : undefined;\n\n const router = Router();\n\n router.use(helmet.frameguard({ action: 'deny' }));\n\n const publicDistDir = resolvePath(appDistDir, 'public');\n\n const enablePublicEntryPoint = await fs.pathExists(publicDistDir);\n\n if (enablePublicEntryPoint) {\n logger.info(\n `App is running in protected mode, serving public content from ${publicDistDir}`,\n );\n\n const publicRouter = Router();\n\n publicRouter.use(async (req, res, next) => {\n try {\n const credentials = await httpAuth.credentials(req, {\n allow: ['user', 'service', 'none'],\n allowLimitedAccess: true,\n });\n\n if (credentials.principal.type === 'none') {\n next();\n } else {\n next('router');\n }\n } catch {\n // If we fail to authenticate, make sure the session cookie is cleared\n // and continue as unauthenticated. If the user is logged in they will\n // immediately be redirected back to the protected app via the POST.\n await httpAuth.issueUserCookie(res, {\n credentials: await auth.getNoneCredentials(),\n });\n next();\n }\n });\n\n publicRouter.post(\n '*',\n express.urlencoded({ extended: true }),\n async (req, res, next) => {\n if (req.body.type === 'sign-in') {\n const credentials = await auth.authenticate(req.body.token);\n\n if (!auth.isPrincipal(credentials, 'user')) {\n throw new AuthenticationError('Invalid token, not a user');\n }\n\n await httpAuth.issueUserCookie(res, {\n credentials,\n });\n\n // Resume as if it was a GET request towards the outer protected router, serving index.html\n req.method = 'GET';\n next('router');\n } else {\n throw new InputError(\n 'Invalid POST request to app-backend wildcard endpoint',\n );\n }\n },\n );\n\n publicRouter.use(\n await createEntryPointRouter({\n logger: logger.child({ entry: 'public' }),\n rootDir: publicDistDir,\n assetStore: assetStore?.withNamespace('public'),\n appConfigs, // TODO(Rugvip): We should not be including the full config here\n }),\n );\n\n router.use(publicRouter);\n }\n\n router.use(\n await createEntryPointRouter({\n logger: logger.child({ entry: 'main' }),\n rootDir: appDistDir,\n assetStore,\n staticFallbackHandler,\n appConfigs,\n }),\n );\n\n return router;\n}\n\nasync function createEntryPointRouter({\n logger,\n rootDir,\n assetStore,\n staticFallbackHandler,\n appConfigs,\n}: {\n logger: LoggerService;\n rootDir: string;\n assetStore?: StaticAssetsStore;\n staticFallbackHandler?: express.Handler;\n appConfigs?: AppConfig[];\n}) {\n const staticDir = resolvePath(rootDir, 'static');\n\n const injectResult =\n appConfigs &&\n (await injectConfig({ appConfigs, logger, rootDir, staticDir }));\n\n const router = Router();\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(staticDir, {\n setHeaders: (res, path) => {\n if (injectResult?.injectedPath === path) {\n res.setHeader('Cache-Control', CACHE_CONTROL_REVALIDATE_CACHE);\n } else {\n res.setHeader('Cache-Control', CACHE_CONTROL_MAX_CACHE);\n }\n },\n }),\n );\n\n if (assetStore) {\n const assets = await findStaticAssets(staticDir);\n await assetStore.storeAssets(assets);\n // Remove any assets that are older than 7 days\n await assetStore.trimAssets({ maxAgeSeconds: 60 * 60 * 24 * 7 });\n\n staticRouter.use(createStaticAssetMiddleware(assetStore));\n }\n\n if (staticFallbackHandler) {\n staticRouter.use(staticFallbackHandler);\n }\n staticRouter.use((_req: Request, res: Response) => {\n res.status(404).end();\n });\n\n router.use('/static', staticRouter);\n\n const rootRouter = Router();\n rootRouter.use((req, _res, next) => {\n // Make sure / and /index.html are handled by the HTML5 route below\n if (req.path === '/' || req.path === '/index.html') {\n next('router');\n } else {\n next();\n }\n });\n rootRouter.use(\n express.static(rootDir, {\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.use(rootRouter);\n\n // HTML5 routing\n router.get('/*', (_req, res) => {\n if (injectResult?.indexHtmlContent) {\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\n res.setHeader('Cache-Control', CACHE_CONTROL_NO_CACHE);\n res.send(injectResult.indexHtmlContent);\n } else {\n res.sendFile(resolvePath(rootDir, '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\n return router;\n}\n"],"names":["resolvePackagePath","resolvePath","fs","Router","readFrontendConfig","StaticAssetsStore","helmet","express","AuthenticationError","InputError","injectConfig","CACHE_CONTROL_REVALIDATE_CACHE","CACHE_CONTROL_MAX_CACHE","findStaticAssets","createStaticAssetMiddleware","CACHE_CONTROL_NO_CACHE"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkGA,eAAsB,aACpB,OAAA,EACyB;AACzB,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,MAAA;AAAA,IACA,cAAA;AAAA,IACA,qBAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,yBAAyB,MAAA,CAAO,kBAAA;AAAA,IACpC;AAAA,GACF;AACA,EAAA,MAAM,6BAA6B,MAAA,CAAO,kBAAA;AAAA,IACxC;AAAA,GACF;AAEA,EAAA,MAAM,UAAA,GAAaA,mCAAA,CAAmB,cAAA,EAAgB,MAAM,CAAA;AAC5D,EAAA,MAAM,SAAA,GAAYC,YAAA,CAAY,UAAA,EAAY,QAAQ,CAAA;AAElD,EAAA,IAAI,CAAE,MAAMC,mBAAA,CAAG,UAAA,CAAW,SAAS,CAAA,EAAI;AACrC,IAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AACzC,MAAA,MAAA,CAAO,KAAA;AAAA,QACL,uCAAuC,SAAS,C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,IAAI,UAAU,CAAA;AAGrB,EAAA,MAAA,CAAO,GAAA,CAAI,IAAA,EAAM,CAAC,IAAA,EAAM,GAAA,KAAQ;AAC9B,IAAA,IAAI,cAAc,gBAAA,EAAkB;AAClC,MAAA,GAAA,CAAI,SAAA,CAAU,gBAAgB,0BAA0B,CAAA;AACxD,MAAA,GAAA,CAAI,SAAA,CAAU,iBAAiBA,8BAAsB,CAAA;AACrD,MAAA,GAAA,CAAI,IAAA,CAAK,aAAa,gBAAgB,CAAA;AAAA,IACxC,CAAA,MAAO;AACL,MAAA,GAAA,CAAI,QAAA,CAASd,YAAA,CAAY,OAAA,EAAS,YAAY,CAAA,EAAG;AAAA,QAC/C,OAAA,EAAS;AAAA;AAAA;AAAA,UAGP,eAAA,EAAiBc;AAAA;AACnB,OACD,CAAA;AAAA,IACH;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;;;;"}
1
+ {"version":3,"file":"router.cjs.js","sources":["../../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 {\n DatabaseService,\n resolvePackagePath,\n RootConfigService,\n} from '@backstage/backend-plugin-api';\nimport type { AppConfig } from '@backstage/config';\nimport helmet from 'helmet';\nimport express, { Request, Response } from 'express';\nimport Router from 'express-promise-router';\nimport fs from 'fs-extra';\nimport { resolve as resolvePath } from 'node:path';\nimport {\n createStaticAssetMiddleware,\n findStaticAssets,\n StaticAssetsStore,\n} from '../lib/assets';\nimport {\n CACHE_CONTROL_MAX_CACHE,\n CACHE_CONTROL_NO_CACHE,\n CACHE_CONTROL_REVALIDATE_CACHE,\n} from '../lib/headers';\nimport type { ConfigSchema } from '@backstage/config-loader';\nimport {\n AuthService,\n HttpAuthService,\n LoggerService,\n} from '@backstage/backend-plugin-api';\nimport { AuthenticationError, InputError } from '@backstage/errors';\nimport { injectConfig, readFrontendConfig } from '../lib/config';\n\n// express uses mime v1 while we only have types for mime v2\ntype Mime = { lookup(arg0: string): string };\n\n/**\n * @internal\n */\nexport interface RouterOptions {\n config: RootConfigService;\n logger: LoggerService;\n auth: AuthService;\n httpAuth: HttpAuthService;\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: DatabaseService;\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 *\n * Provides a ConfigSchema.\n *\n */\n schema?: ConfigSchema;\n}\n\n/**\n * @internal\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n const {\n config,\n logger,\n appPackageName,\n staticFallbackHandler,\n auth,\n httpAuth,\n schema,\n } = options;\n\n const disableConfigInjection = config.getOptionalBoolean(\n 'app.disableConfigInjection',\n );\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 const appConfigs = disableConfigInjection\n ? undefined\n : await readFrontendConfig({\n config,\n appDistDir,\n env: process.env,\n schema,\n });\n\n const assetStore = !disableStaticFallbackCache\n ? await StaticAssetsStore.create({\n logger,\n database: options.database,\n })\n : undefined;\n\n const router = Router();\n\n router.use(helmet.frameguard({ action: 'deny' }));\n\n const publicDistDir = resolvePath(appDistDir, 'public');\n\n const enablePublicEntryPoint = await fs.pathExists(publicDistDir);\n\n if (enablePublicEntryPoint) {\n logger.info(\n `App is running in protected mode, serving public content from ${publicDistDir}`,\n );\n\n const publicRouter = Router();\n\n publicRouter.use(async (req, res, next) => {\n try {\n const credentials = await httpAuth.credentials(req, {\n allow: ['user', 'service', 'none'],\n allowLimitedAccess: true,\n });\n\n if (credentials.principal.type === 'none') {\n next();\n } else {\n next('router');\n }\n } catch {\n // If we fail to authenticate, make sure the session cookie is cleared\n // and continue as unauthenticated. If the user is logged in they will\n // immediately be redirected back to the protected app via the POST.\n await httpAuth.issueUserCookie(res, {\n credentials: await auth.getNoneCredentials(),\n });\n next();\n }\n });\n\n publicRouter.post(\n '*',\n express.urlencoded({ extended: true }),\n async (req, res, next) => {\n if (req.body.type === 'sign-in') {\n const credentials = await auth.authenticate(req.body.token);\n\n if (!auth.isPrincipal(credentials, 'user')) {\n throw new AuthenticationError('Invalid token, not a user');\n }\n\n await httpAuth.issueUserCookie(res, {\n credentials,\n });\n\n // Resume as if it was a GET request towards the outer protected router, serving index.html\n req.method = 'GET';\n next('router');\n } else {\n throw new InputError(\n 'Invalid POST request to app-backend wildcard endpoint',\n );\n }\n },\n );\n\n publicRouter.use(\n await createEntryPointRouter({\n logger: logger.child({ entry: 'public' }),\n rootDir: publicDistDir,\n assetStore: assetStore?.withNamespace('public'),\n appConfigs, // TODO(Rugvip): We should not be including the full config here\n }),\n );\n\n router.use(publicRouter);\n }\n\n router.use(\n await createEntryPointRouter({\n logger: logger.child({ entry: 'main' }),\n rootDir: appDistDir,\n assetStore,\n staticFallbackHandler,\n appConfigs,\n }),\n );\n\n return router;\n}\n\nasync function createEntryPointRouter({\n logger,\n rootDir,\n assetStore,\n staticFallbackHandler,\n appConfigs,\n}: {\n logger: LoggerService;\n rootDir: string;\n assetStore?: StaticAssetsStore;\n staticFallbackHandler?: express.Handler;\n appConfigs?: AppConfig[];\n}) {\n const staticDir = resolvePath(rootDir, 'static');\n\n const injectResult =\n appConfigs &&\n (await injectConfig({ appConfigs, logger, rootDir, staticDir }));\n\n const router = Router();\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(staticDir, {\n setHeaders: (res, path) => {\n if (injectResult?.injectedPath === path) {\n res.setHeader('Cache-Control', CACHE_CONTROL_REVALIDATE_CACHE);\n } else {\n res.setHeader('Cache-Control', CACHE_CONTROL_MAX_CACHE);\n }\n },\n }),\n );\n\n if (assetStore) {\n const assets = await findStaticAssets(staticDir);\n await assetStore.storeAssets(assets);\n // Remove any assets that are older than 7 days\n await assetStore.trimAssets({ maxAgeSeconds: 60 * 60 * 24 * 7 });\n\n staticRouter.use(createStaticAssetMiddleware(assetStore));\n }\n\n if (staticFallbackHandler) {\n staticRouter.use(staticFallbackHandler);\n }\n staticRouter.use((_req: Request, res: Response) => {\n res.status(404).end();\n });\n\n router.use('/static', staticRouter);\n\n const rootRouter = Router();\n rootRouter.use((req, _res, next) => {\n // Make sure / and /index.html are handled by the HTML5 route below\n if (req.path === '/' || req.path === '/index.html') {\n next('router');\n } else {\n next();\n }\n });\n rootRouter.use(\n express.static(rootDir, {\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.use(rootRouter);\n\n // HTML5 routing\n router.get('/*', (_req, res) => {\n if (injectResult?.indexHtmlContent) {\n res.setHeader('Content-Type', 'text/html; charset=utf-8');\n res.setHeader('Cache-Control', CACHE_CONTROL_NO_CACHE);\n res.send(injectResult.indexHtmlContent);\n } else {\n res.sendFile(resolvePath(rootDir, '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\n return router;\n}\n"],"names":["resolvePackagePath","resolvePath","fs","Router","readFrontendConfig","StaticAssetsStore","helmet","express","AuthenticationError","InputError","injectConfig","CACHE_CONTROL_REVALIDATE_CACHE","CACHE_CONTROL_MAX_CACHE","findStaticAssets","createStaticAssetMiddleware","CACHE_CONTROL_NO_CACHE"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAkGA,eAAsB,aACpB,OAAA,EACyB;AACzB,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,MAAA;AAAA,IACA,cAAA;AAAA,IACA,qBAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA;AAAA,GACF,GAAI,OAAA;AAEJ,EAAA,MAAM,yBAAyB,MAAA,CAAO,kBAAA;AAAA,IACpC;AAAA,GACF;AACA,EAAA,MAAM,6BAA6B,MAAA,CAAO,kBAAA;AAAA,IACxC;AAAA,GACF;AAEA,EAAA,MAAM,UAAA,GAAaA,mCAAA,CAAmB,cAAA,EAAgB,MAAM,CAAA;AAC5D,EAAA,MAAM,SAAA,GAAYC,iBAAA,CAAY,UAAA,EAAY,QAAQ,CAAA;AAElD,EAAA,IAAI,CAAE,MAAMC,mBAAA,CAAG,UAAA,CAAW,SAAS,CAAA,EAAI;AACrC,IAAA,IAAI,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,EAAc;AACzC,MAAA,MAAA,CAAO,KAAA;AAAA,QACL,uCAAuC,SAAS,CA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O,IAAI,UAAU,CAAA;AAGrB,EAAA,MAAA,CAAO,GAAA,CAAI,IAAA,EAAM,CAAC,IAAA,EAAM,GAAA,KAAQ;AAC9B,IAAA,IAAI,cAAc,gBAAA,EAAkB;AAClC,MAAA,GAAA,CAAI,SAAA,CAAU,gBAAgB,0BAA0B,CAAA;AACxD,MAAA,GAAA,CAAI,SAAA,CAAU,iBAAiBA,8BAAsB,CAAA;AACrD,MAAA,GAAA,CAAI,IAAA,CAAK,aAAa,gBAAgB,CAAA;AAAA,IACxC,CAAA,MAAO;AACL,MAAA,GAAA,CAAI,QAAA,CAASd,iBAAA,CAAY,OAAA,EAAS,YAAY,CAAA,EAAG;AAAA,QAC/C,OAAA,EAAS;AAAA;AAAA;AAAA,UAGP,eAAA,EAAiBc;AAAA;AACnB,OACD,CAAA;AAAA,IACH;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAA;AACT;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-app-backend",
3
- "version": "0.5.10",
3
+ "version": "0.5.11-next.0",
4
4
  "description": "A Backstage backend plugin that serves the Backstage frontend app",
5
5
  "backstage": {
6
6
  "role": "backend-plugin",
@@ -62,13 +62,13 @@
62
62
  "test": "backstage-cli package test"
63
63
  },
64
64
  "dependencies": {
65
- "@backstage/backend-plugin-api": "^1.6.1",
66
- "@backstage/config": "^1.3.6",
67
- "@backstage/config-loader": "^1.10.7",
68
- "@backstage/errors": "^1.2.7",
69
- "@backstage/plugin-app-node": "^0.1.41",
70
- "@backstage/plugin-auth-node": "^0.6.11",
71
- "@backstage/types": "^1.2.2",
65
+ "@backstage/backend-plugin-api": "1.7.0-next.0",
66
+ "@backstage/config": "1.3.6",
67
+ "@backstage/config-loader": "1.10.8-next.0",
68
+ "@backstage/errors": "1.2.7",
69
+ "@backstage/plugin-app-node": "0.1.42-next.0",
70
+ "@backstage/plugin-auth-node": "0.6.12-next.0",
71
+ "@backstage/types": "1.2.2",
72
72
  "express": "^4.22.0",
73
73
  "express-promise-router": "^4.1.0",
74
74
  "fs-extra": "^11.2.0",
@@ -80,11 +80,11 @@
80
80
  "yn": "^4.0.0"
81
81
  },
82
82
  "devDependencies": {
83
- "@backstage/backend-app-api": "^1.4.1",
84
- "@backstage/backend-defaults": "^0.15.0",
85
- "@backstage/backend-test-utils": "^1.10.3",
86
- "@backstage/cli": "^0.35.2",
87
- "@backstage/types": "^1.2.2",
83
+ "@backstage/backend-app-api": "1.5.0-next.0",
84
+ "@backstage/backend-defaults": "0.15.1-next.0",
85
+ "@backstage/backend-test-utils": "1.10.4-next.0",
86
+ "@backstage/cli": "0.35.3-next.0",
87
+ "@backstage/types": "1.2.2",
88
88
  "@types/express": "^4.17.6",
89
89
  "@types/supertest": "^2.0.8",
90
90
  "supertest": "^7.0.0"