@backstage/plugin-app-backend 0.3.34-next.2 → 0.3.35-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 +29 -0
- package/dist/index.cjs.js +76 -39
- package/dist/index.cjs.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @backstage/plugin-app-backend
|
|
2
2
|
|
|
3
|
+
## 0.3.35-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/backend-common@0.15.0-next.0
|
|
9
|
+
|
|
10
|
+
## 0.3.34
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- a70869e775: Updated dependency `msw` to `^0.43.0`.
|
|
15
|
+
- 4e9a90e307: Updated dependency `luxon` to `^3.0.0`.
|
|
16
|
+
- 8006d0f9bf: Updated dependency `msw` to `^0.44.0`.
|
|
17
|
+
- 679b32172e: Updated dependency `knex` to `^2.0.0`.
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
- @backstage/backend-common@0.14.1
|
|
20
|
+
- @backstage/config-loader@1.1.3
|
|
21
|
+
|
|
22
|
+
## 0.3.34-next.3
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- a70869e775: Updated dependency `msw` to `^0.43.0`.
|
|
27
|
+
- 4e9a90e307: Updated dependency `luxon` to `^3.0.0`.
|
|
28
|
+
- Updated dependencies
|
|
29
|
+
- @backstage/backend-common@0.14.1-next.3
|
|
30
|
+
- @backstage/config-loader@1.1.3-next.1
|
|
31
|
+
|
|
3
32
|
## 0.3.34-next.2
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -33,12 +33,18 @@ async function injectConfig(options) {
|
|
|
33
33
|
const content = await fs__default["default"].readFile(path$1, "utf8");
|
|
34
34
|
if (content.includes("__APP_INJECTED_RUNTIME_CONFIG__")) {
|
|
35
35
|
logger.info(`Injecting env config into ${jsFile}`);
|
|
36
|
-
const newContent = content.replace(
|
|
36
|
+
const newContent = content.replace(
|
|
37
|
+
'"__APP_INJECTED_RUNTIME_CONFIG__"',
|
|
38
|
+
injected
|
|
39
|
+
);
|
|
37
40
|
await fs__default["default"].writeFile(path$1, newContent, "utf8");
|
|
38
41
|
return;
|
|
39
42
|
} else if (content.includes("__APP_INJECTED_CONFIG_MARKER__")) {
|
|
40
43
|
logger.info(`Replacing injected env config in ${jsFile}`);
|
|
41
|
-
const newContent = content.replace(
|
|
44
|
+
const newContent = content.replace(
|
|
45
|
+
/\/\*__APP_INJECTED_CONFIG_MARKER__\*\/.*\/\*__INJECTED_END__\*\//,
|
|
46
|
+
injected
|
|
47
|
+
);
|
|
42
48
|
await fs__default["default"].writeFile(path$1, newContent, "utf8");
|
|
43
49
|
return;
|
|
44
50
|
}
|
|
@@ -53,10 +59,15 @@ async function readConfigs(options) {
|
|
|
53
59
|
const serializedSchema = await fs__default["default"].readJson(schemaPath);
|
|
54
60
|
try {
|
|
55
61
|
const schema = await configLoader.loadConfigSchema({ serialized: serializedSchema });
|
|
56
|
-
const frontendConfigs = await schema.process(
|
|
62
|
+
const frontendConfigs = await schema.process(
|
|
63
|
+
[{ data: config.get(), context: "app" }],
|
|
64
|
+
{ visibility: ["frontend"], withDeprecatedKeys: true }
|
|
65
|
+
);
|
|
57
66
|
appConfigs.push(...frontendConfigs);
|
|
58
67
|
} catch (error) {
|
|
59
|
-
throw new Error(
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Invalid app bundle schema. If this error is unexpected you need to run \`yarn build\` in the app. If that doesn't help you should make sure your config schema is correct and rebuild the app bundle again. Caused by the following schema error, ${error}`
|
|
70
|
+
);
|
|
60
71
|
}
|
|
61
72
|
}
|
|
62
73
|
return appConfigs;
|
|
@@ -81,7 +92,10 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
81
92
|
return value;
|
|
82
93
|
};
|
|
83
94
|
var _db, _logger;
|
|
84
|
-
const migrationsDir = backendCommon.resolvePackagePath(
|
|
95
|
+
const migrationsDir = backendCommon.resolvePackagePath(
|
|
96
|
+
"@backstage/plugin-app-backend",
|
|
97
|
+
"migrations"
|
|
98
|
+
);
|
|
85
99
|
const _StaticAssetsStore = class {
|
|
86
100
|
constructor(options) {
|
|
87
101
|
__privateAdd(this, _db, void 0);
|
|
@@ -96,13 +110,24 @@ const _StaticAssetsStore = class {
|
|
|
96
110
|
return new _StaticAssetsStore(options);
|
|
97
111
|
}
|
|
98
112
|
async storeAssets(assets) {
|
|
99
|
-
const existingRows = await __privateGet(this, _db).call(this, "static_assets_cache").whereIn(
|
|
113
|
+
const existingRows = await __privateGet(this, _db).call(this, "static_assets_cache").whereIn(
|
|
114
|
+
"path",
|
|
115
|
+
assets.map((a) => a.path)
|
|
116
|
+
);
|
|
100
117
|
const existingAssetPaths = new Set(existingRows.map((r) => r.path));
|
|
101
|
-
const [modified, added] = partition__default["default"](
|
|
102
|
-
|
|
118
|
+
const [modified, added] = partition__default["default"](
|
|
119
|
+
assets,
|
|
120
|
+
(asset) => existingAssetPaths.has(asset.path)
|
|
121
|
+
);
|
|
122
|
+
__privateGet(this, _logger).info(
|
|
123
|
+
`Storing ${modified.length} updated assets and ${added.length} new assets`
|
|
124
|
+
);
|
|
103
125
|
await __privateGet(this, _db).call(this, "static_assets_cache").update({
|
|
104
126
|
last_modified_at: __privateGet(this, _db).fn.now()
|
|
105
|
-
}).whereIn(
|
|
127
|
+
}).whereIn(
|
|
128
|
+
"path",
|
|
129
|
+
modified.map((a) => a.path)
|
|
130
|
+
);
|
|
106
131
|
for (const asset of added) {
|
|
107
132
|
await __privateGet(this, _db).call(this, "static_assets_cache").insert({
|
|
108
133
|
path: asset.path,
|
|
@@ -125,7 +150,11 @@ const _StaticAssetsStore = class {
|
|
|
125
150
|
}
|
|
126
151
|
async trimAssets(options) {
|
|
127
152
|
const { maxAgeSeconds } = options;
|
|
128
|
-
await __privateGet(this, _db).call(this, "static_assets_cache").where(
|
|
153
|
+
await __privateGet(this, _db).call(this, "static_assets_cache").where(
|
|
154
|
+
"last_modified_at",
|
|
155
|
+
"<=",
|
|
156
|
+
__privateGet(this, _db).client.config.client.includes("sqlite3") ? __privateGet(this, _db).raw(`datetime('now', ?)`, [`-${maxAgeSeconds} seconds`]) : __privateGet(this, _db).raw(`now() + interval '${-maxAgeSeconds} seconds'`)
|
|
157
|
+
).delete();
|
|
129
158
|
}
|
|
130
159
|
};
|
|
131
160
|
let StaticAssetsStore = _StaticAssetsStore;
|
|
@@ -153,23 +182,25 @@ function createStaticAssetMiddleware(store) {
|
|
|
153
182
|
next();
|
|
154
183
|
return;
|
|
155
184
|
}
|
|
156
|
-
Promise.resolve(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
185
|
+
Promise.resolve(
|
|
186
|
+
(async () => {
|
|
187
|
+
const path$1 = req.path.startsWith("/") ? req.path.slice(1) : req.path;
|
|
188
|
+
const asset = await store.getAsset(path$1);
|
|
189
|
+
if (!asset) {
|
|
190
|
+
next();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const ext = path.extname(asset.path);
|
|
194
|
+
if (ext) {
|
|
195
|
+
res.type(ext);
|
|
196
|
+
} else {
|
|
197
|
+
res.type("bin");
|
|
198
|
+
}
|
|
199
|
+
res.setHeader("Cache-Control", CACHE_CONTROL_MAX_CACHE);
|
|
200
|
+
res.setHeader("Last-Modified", asset.lastModifiedAt.toUTCString());
|
|
201
|
+
res.send(asset.content);
|
|
202
|
+
})()
|
|
203
|
+
).catch(next);
|
|
173
204
|
};
|
|
174
205
|
}
|
|
175
206
|
|
|
@@ -178,7 +209,9 @@ async function createRouter(options) {
|
|
|
178
209
|
const appDistDir = backendCommon.resolvePackagePath(appPackageName, "dist");
|
|
179
210
|
const staticDir = path.resolve(appDistDir, "static");
|
|
180
211
|
if (!await fs__default["default"].pathExists(staticDir)) {
|
|
181
|
-
logger.warn(
|
|
212
|
+
logger.warn(
|
|
213
|
+
`Can't serve static app content from ${staticDir}, directory doesn't exist`
|
|
214
|
+
);
|
|
182
215
|
return Router__default["default"]();
|
|
183
216
|
}
|
|
184
217
|
logger.info(`Serving static app content from ${appDistDir}`);
|
|
@@ -193,11 +226,13 @@ async function createRouter(options) {
|
|
|
193
226
|
const router = Router__default["default"]();
|
|
194
227
|
router.use(helmet__default["default"].frameguard({ action: "deny" }));
|
|
195
228
|
const staticRouter = Router__default["default"]();
|
|
196
|
-
staticRouter.use(
|
|
197
|
-
|
|
198
|
-
res
|
|
199
|
-
|
|
200
|
-
|
|
229
|
+
staticRouter.use(
|
|
230
|
+
express__default["default"].static(path.resolve(appDistDir, "static"), {
|
|
231
|
+
setHeaders: (res) => {
|
|
232
|
+
res.setHeader("Cache-Control", CACHE_CONTROL_MAX_CACHE);
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
);
|
|
201
236
|
if (options.database) {
|
|
202
237
|
const store = await StaticAssetsStore.create({
|
|
203
238
|
logger,
|
|
@@ -213,13 +248,15 @@ async function createRouter(options) {
|
|
|
213
248
|
}
|
|
214
249
|
staticRouter.use(backendCommon.notFoundHandler());
|
|
215
250
|
router.use("/static", staticRouter);
|
|
216
|
-
router.use(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
251
|
+
router.use(
|
|
252
|
+
express__default["default"].static(appDistDir, {
|
|
253
|
+
setHeaders: (res, path) => {
|
|
254
|
+
if (express__default["default"].static.mime.lookup(path) === "text/html") {
|
|
255
|
+
res.setHeader("Cache-Control", CACHE_CONTROL_NO_CACHE);
|
|
256
|
+
}
|
|
220
257
|
}
|
|
221
|
-
}
|
|
222
|
-
|
|
258
|
+
})
|
|
259
|
+
);
|
|
223
260
|
router.get("/*", (_req, res) => {
|
|
224
261
|
res.sendFile(path.resolve(appDistDir, "index.html"), {
|
|
225
262
|
headers: {
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.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 { resolvePackagePath } 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: Knex;\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 await options.database.migrate.latest({\n directory: migrationsDir,\n });\n return new StaticAssetsStore(options);\n }\n\n private constructor(options: StaticAssetsStoreOptions) {\n this.#db = options.database;\n this.#logger = options.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\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\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 logger.warn(\n `Can't serve static app content from ${staticDir}, directory doesn't exist`,\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: await options.database.getClient(),\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":";;;;;;;;;;;;;;;;;;;;;;;;AAGO,eAAe,YAAY,CAAC,OAAO,EAAE;AAC5C,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;AACpD,EAAE,MAAM,KAAK,GAAG,MAAMA,sBAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAC5C,EAAE,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/D,EAAE,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AAC9E,EAAE,MAAM,QAAQ,GAAG,CAAC,mCAAmC,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAC;AAC5F,EAAE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;AAChC,IAAI,MAAMC,MAAI,GAAGC,YAAW,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAChD,IAAI,MAAM,OAAO,GAAG,MAAMF,sBAAE,CAAC,QAAQ,CAACC,MAAI,EAAE,MAAM,CAAC,CAAC;AACpD,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,iCAAiC,CAAC,EAAE;AAC7D,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,0BAA0B,EAAE,MAAM,CAAC,CAA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AE,GAAG,CAAC,EAAE,CAAC,CAAC;AAChE,IAAI,YAAY,CAAC,GAAG,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC,CAAC;AACzD,GAAG;AACH,EAAE,IAAI,qBAAqB,EAAE;AAC7B,IAAI,YAAY,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAC5C,GAAG;AACH,EAAE,YAAY,CAAC,GAAG,CAACY,6BAAe,EAAE,CAAC,CAAC;AACtC,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AACtC,EAAE,MAAM,CAAC,GAAG,CAACD,2BAAO,CAAC,MAAM,CAAC,UAAU,EAAE;AACxC,IAAI,UAAU,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK;AAC/B,MAAM,IAAIA,2BAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,WAAW,EAAE;AAC5D,QAAQ,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,sBAAsB,CAAC,CAAC;AAC/D,OAAO;AACP,KAAK;AACL,GAAG,CAAC,CAAC,CAAC;AACN,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK;AAClC,IAAI,GAAG,CAAC,QAAQ,CAACX,YAAW,CAAC,UAAU,EAAE,YAAY,CAAC,EAAE;AACxD,MAAM,OAAO,EAAE;AACf,QAAQ,eAAe,EAAE,sBAAsB;AAC/C,OAAO;AACP,KAAK,CAAC,CAAC;AACP,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
|
|
1
|
+
{"version":3,"file":"index.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 { resolvePackagePath } 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: Knex;\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 await options.database.migrate.latest({\n directory: migrationsDir,\n });\n return new StaticAssetsStore(options);\n }\n\n private constructor(options: StaticAssetsStoreOptions) {\n this.#db = options.database;\n this.#logger = options.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\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\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 logger.warn(\n `Can't serve static app content from ${staticDir}, directory doesn't exist`,\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: await options.database.getClient(),\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":";;;;;;;;;;;;;;;;;;;;;;;;AAGO,eAAe,YAAY,CAAC,OAAO,EAAE;AAC5C,EAAE,MAAM,EAAE,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C;AAC5C,GAAG;AACH,EAAE,YAAY,CAAC,GAAG,CAACY,6BAAe,EAAE,CAAC,CAAC;AACtC,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AACtC,EAAE,MAAM,CAAC,GAAG;AACZ,IAAID,2BAAO,CAAC,MAAM,CAAC,UAAU,EAAE;AAC/B,MAAM,UAAU,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK;AACjC,QAAQ,IAAIA,2BAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,WAAW,EAAE;AAC9D,UAAU,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,sBAAsB,CAAC,CAAC;AACjE,SAAS;AACT,OAAO;AACP,KAAK,CAAC;AACN,GAAG,CAAC;AACJ,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK;AAClC,IAAI,GAAG,CAAC,QAAQ,CAACX,YAAW,CAAC,UAAU,EAAE,YAAY,CAAC,EAAE;AACxD,MAAM,OAAO,EAAE;AACf,QAAQ,eAAe,EAAE,sBAAsB;AAC/C,OAAO;AACP,KAAK,CAAC,CAAC;AACP,GAAG,CAAC,CAAC;AACL,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
|
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.
|
|
4
|
+
"version": "0.3.35-next.0",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"clean": "backstage-cli package clean"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@backstage/backend-common": "^0.
|
|
36
|
+
"@backstage/backend-common": "^0.15.0-next.0",
|
|
37
37
|
"@backstage/config": "^1.0.1",
|
|
38
|
-
"@backstage/config-loader": "^1.1.3
|
|
38
|
+
"@backstage/config-loader": "^1.1.3",
|
|
39
39
|
"@backstage/types": "^1.0.0",
|
|
40
40
|
"@types/express": "^4.17.6",
|
|
41
41
|
"express": "^4.17.1",
|
|
@@ -45,17 +45,17 @@
|
|
|
45
45
|
"helmet": "^5.0.2",
|
|
46
46
|
"knex": "^2.0.0",
|
|
47
47
|
"lodash": "^4.17.21",
|
|
48
|
-
"luxon": "^
|
|
48
|
+
"luxon": "^3.0.0",
|
|
49
49
|
"winston": "^3.2.1",
|
|
50
50
|
"yn": "^4.0.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@backstage/backend-test-utils": "^0.1.
|
|
54
|
-
"@backstage/cli": "^0.18.
|
|
53
|
+
"@backstage/backend-test-utils": "^0.1.27-next.0",
|
|
54
|
+
"@backstage/cli": "^0.18.1-next.0",
|
|
55
55
|
"@backstage/types": "^1.0.0",
|
|
56
56
|
"@types/supertest": "^2.0.8",
|
|
57
57
|
"mock-fs": "^5.1.0",
|
|
58
|
-
"msw": "^0.
|
|
58
|
+
"msw": "^0.44.0",
|
|
59
59
|
"supertest": "^6.1.3"
|
|
60
60
|
},
|
|
61
61
|
"files": [
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"migrations/**/*.{js,d.ts}",
|
|
64
64
|
"static"
|
|
65
65
|
],
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "fc3229c49caf6eced02ed9516199015bf4682664"
|
|
67
67
|
}
|