From 221e951298b01bf9987085189291611185f3be03 Mon Sep 17 00:00:00 2001 From: Luka Siric Date: Wed, 24 Aug 2022 23:02:56 +0200 Subject: [PATCH 1/7] passing https.cert and https.key options to the webpack dev server Signed-off-by: Luka Siric --- .changeset/fast-paws-press.md | 6 ++++++ app-config.yaml | 7 ++++++- packages/cli/src/lib/bundler/server.ts | 12 +++++++++++- packages/core-app-api/config.d.ts | 20 ++++++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 .changeset/fast-paws-press.md diff --git a/.changeset/fast-paws-press.md b/.changeset/fast-paws-press.md new file mode 100644 index 0000000000..353a2f422c --- /dev/null +++ b/.changeset/fast-paws-press.md @@ -0,0 +1,6 @@ +--- +'@backstage/cli': patch +'@backstage/core-app-api': patch +--- + +Added support for custom certificate for webpack dev server. diff --git a/app-config.yaml b/app-config.yaml index 32b53da236..4bbb272d00 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -2,12 +2,17 @@ app: title: Backstage Example App baseUrl: http://localhost:3000 googleAnalyticsTrackingId: # UA-000000-0 + # https: + # credentials: + # cert: + # $file '\path\to\the\certificate' + # key: + # $file '\path\to\the\private-key' #datadogRum: # clientToken: '123456789' # applicationId: qwerty # site: # datadoghq.eu default = datadoghq.com # env: # optional - support: url: https://github.com/backstage/backstage/issues # Used by common ErrorPage items: # Used by common SupportButton component diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index d573f80e27..3057bcb70b 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -60,7 +60,17 @@ export async function serveBundle(options: ServeOptions) { // See https://github.com/facebookincubator/create-react-app/issues/387. disableDotRule: true, }, - https: url.protocol === 'https:', + https: + url.protocol === 'https:' + ? { + cert: options.frontendConfig.getOptionalString( + 'app.https.credentials.cert', + ), + key: options.frontendConfig.getOptionalString( + 'app.https.credentials.key', + ), + } + : false, host, port, proxy: pkg.proxy, diff --git a/packages/core-app-api/config.d.ts b/packages/core-app-api/config.d.ts index d88c818d11..e5047709d8 100644 --- a/packages/core-app-api/config.d.ts +++ b/packages/core-app-api/config.d.ts @@ -65,6 +65,26 @@ export interface Config { }>; }>; }; + /** + * Running the frontend app with https + */ + https?: { + /** + * Parent object containing certificate and the private key + */ + credentials?: { + /** + * Https Certificate private key. Can be loaded using $file + * @visibility frontend + */ + key?: string; + /** + * Https Certificate. Can be loaded using $file + * @visibility frontend + */ + cert?: string; + }; + }; }; /** From 37763a03840847c1a3c7a054d8e8ca32ef667d1e Mon Sep 17 00:00:00 2001 From: Luka Siric Date: Fri, 26 Aug 2022 12:28:32 +0200 Subject: [PATCH 2/7] fixed comments from benjdlambert Signed-off-by: Luka Siric --- .changeset/fast-paws-press.md | 2 +- app-config.yaml | 6 +++--- packages/cli/src/lib/bundler/server.ts | 5 +++-- packages/core-app-api/config.d.ts | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.changeset/fast-paws-press.md b/.changeset/fast-paws-press.md index 353a2f422c..b9e1893963 100644 --- a/.changeset/fast-paws-press.md +++ b/.changeset/fast-paws-press.md @@ -1,6 +1,6 @@ --- '@backstage/cli': patch -'@backstage/core-app-api': patch +'@backstage/core-app-api': minor --- Added support for custom certificate for webpack dev server. diff --git a/app-config.yaml b/app-config.yaml index 4bbb272d00..fc7215ceb8 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -3,11 +3,11 @@ app: baseUrl: http://localhost:3000 googleAnalyticsTrackingId: # UA-000000-0 # https: - # credentials: + # certificate: # cert: - # $file '\path\to\the\certificate' + # $file: '\path\to\the\certificate' # key: - # $file '\path\to\the\private-key' + # $file: '\path\to\the\private-key' #datadogRum: # clientToken: '123456789' # applicationId: qwerty diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index 3057bcb70b..2e362cd050 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -40,6 +40,7 @@ export async function serveBundle(options: ServeOptions) { isDev: true, baseUrl: url, }); + const compiler = webpack(config); const server = new WebpackDevServer( @@ -64,10 +65,10 @@ export async function serveBundle(options: ServeOptions) { url.protocol === 'https:' ? { cert: options.frontendConfig.getOptionalString( - 'app.https.credentials.cert', + 'app.https.certificate.cert', ), key: options.frontendConfig.getOptionalString( - 'app.https.credentials.key', + 'app.https.certificate.key', ), } : false, diff --git a/packages/core-app-api/config.d.ts b/packages/core-app-api/config.d.ts index e5047709d8..42b1fd9245 100644 --- a/packages/core-app-api/config.d.ts +++ b/packages/core-app-api/config.d.ts @@ -72,14 +72,14 @@ export interface Config { /** * Parent object containing certificate and the private key */ - credentials?: { + certificate?: { /** - * Https Certificate private key. Can be loaded using $file + * Https Certificate private key. Use $file to load in a file * @visibility frontend */ key?: string; /** - * Https Certificate. Can be loaded using $file + * Https Certificate. Use $file to load in a file * @visibility frontend */ cert?: string; From 08eb42afdcb4fe9caf8ce6525719aee17f0057ed Mon Sep 17 00:00:00 2001 From: Luka Siric Date: Mon, 29 Aug 2022 12:30:48 +0200 Subject: [PATCH 3/7] added backend config to startFrontend. set cert key visibility to secret. Signed-off-by: Luka Siric --- packages/cli/src/lib/bundler/server.ts | 2 +- packages/cli/src/lib/bundler/types.ts | 2 ++ packages/cli/src/lib/config.ts | 9 +++++++++ packages/core-app-api/config.d.ts | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index 2e362cd050..a05baf5355 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -67,7 +67,7 @@ export async function serveBundle(options: ServeOptions) { cert: options.frontendConfig.getOptionalString( 'app.https.certificate.cert', ), - key: options.frontendConfig.getOptionalString( + key: options.backendConfig.getOptionalString( 'app.https.certificate.key', ), } diff --git a/packages/cli/src/lib/bundler/types.ts b/packages/cli/src/lib/bundler/types.ts index 4d6d2e5c9e..0d9d0f7af4 100644 --- a/packages/cli/src/lib/bundler/types.ts +++ b/packages/cli/src/lib/bundler/types.ts @@ -31,6 +31,8 @@ export type ServeOptions = BundlingPathsOptions & { checksEnabled: boolean; frontendConfig: Config; frontendAppConfigs: AppConfig[]; + backendConfig: Config; + backendAppConfigs: AppConfig[]; }; export type BuildOptions = BundlingPathsOptions & { diff --git a/packages/cli/src/lib/config.ts b/packages/cli/src/lib/config.ts index e7ceeadf08..691c0ff83c 100644 --- a/packages/cli/src/lib/config.ts +++ b/packages/cli/src/lib/config.ts @@ -96,11 +96,20 @@ export async function loadCliConfig(options: Options) { }); const frontendConfig = ConfigReader.fromConfigs(frontendAppConfigs); + const backendAppConfigs = schema.process(appConfigs, { + visibility: ['frontend', 'backend', 'secret'], + withFilteredKeys: options.withFilteredKeys, + withDeprecatedKeys: options.withDeprecatedKeys, + }); + const backendConfig = ConfigReader.fromConfigs(backendAppConfigs); + return { schema, appConfigs, frontendConfig, frontendAppConfigs, + backendAppConfigs, + backendConfig, }; } catch (error) { const maybeSchemaError = error as Error & { messages?: string[] }; diff --git a/packages/core-app-api/config.d.ts b/packages/core-app-api/config.d.ts index 42b1fd9245..6b707987e5 100644 --- a/packages/core-app-api/config.d.ts +++ b/packages/core-app-api/config.d.ts @@ -75,7 +75,7 @@ export interface Config { certificate?: { /** * Https Certificate private key. Use $file to load in a file - * @visibility frontend + * @visibility secret */ key?: string; /** From eef0522644ed9d50fcc7fd69e7a712c2719b47ab Mon Sep 17 00:00:00 2001 From: Luka Siric Date: Tue, 30 Aug 2022 16:33:47 +0200 Subject: [PATCH 4/7] resolved @Rugvip comments Signed-off-by: Luka Siric --- app-config.yaml | 6 ---- packages/cli/config.d.ts | 40 ++++++++++++++++++++++++++ packages/cli/src/lib/bundler/server.ts | 6 ++-- packages/cli/src/lib/bundler/types.ts | 1 - packages/cli/src/lib/config.ts | 7 +---- packages/core-app-api/config.d.ts | 20 ------------- 6 files changed, 43 insertions(+), 37 deletions(-) create mode 100644 packages/cli/config.d.ts diff --git a/app-config.yaml b/app-config.yaml index fc7215ceb8..7c93d9cbd2 100644 --- a/app-config.yaml +++ b/app-config.yaml @@ -2,12 +2,6 @@ app: title: Backstage Example App baseUrl: http://localhost:3000 googleAnalyticsTrackingId: # UA-000000-0 - # https: - # certificate: - # cert: - # $file: '\path\to\the\certificate' - # key: - # $file: '\path\to\the\private-key' #datadogRum: # clientToken: '123456789' # applicationId: qwerty diff --git a/packages/cli/config.d.ts b/packages/cli/config.d.ts new file mode 100644 index 0000000000..24cc60dac3 --- /dev/null +++ b/packages/cli/config.d.ts @@ -0,0 +1,40 @@ +/* + * Copyright 2022 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export interface Config { + app: { + /** + * Running the frontend app with https + */ + https?: { + /** + * Parent object containing certificate and the private key + */ + certificate?: { + /** + * Https Certificate private key. Use $file to load in a file + * @visibility secret + */ + key: string; + /** + * Https Certificate. Use $file to load in a file + * @visibility secret + */ + cert: string; + }; + }; + }; +} diff --git a/packages/cli/src/lib/bundler/server.ts b/packages/cli/src/lib/bundler/server.ts index a05baf5355..d3f1e8da75 100644 --- a/packages/cli/src/lib/bundler/server.ts +++ b/packages/cli/src/lib/bundler/server.ts @@ -64,12 +64,10 @@ export async function serveBundle(options: ServeOptions) { https: url.protocol === 'https:' ? { - cert: options.frontendConfig.getOptionalString( + cert: options.backendConfig.getString( 'app.https.certificate.cert', ), - key: options.backendConfig.getOptionalString( - 'app.https.certificate.key', - ), + key: options.backendConfig.getString('app.https.certificate.key'), } : false, host, diff --git a/packages/cli/src/lib/bundler/types.ts b/packages/cli/src/lib/bundler/types.ts index 0d9d0f7af4..68260735f9 100644 --- a/packages/cli/src/lib/bundler/types.ts +++ b/packages/cli/src/lib/bundler/types.ts @@ -32,7 +32,6 @@ export type ServeOptions = BundlingPathsOptions & { frontendConfig: Config; frontendAppConfigs: AppConfig[]; backendConfig: Config; - backendAppConfigs: AppConfig[]; }; export type BuildOptions = BundlingPathsOptions & { diff --git a/packages/cli/src/lib/config.ts b/packages/cli/src/lib/config.ts index 691c0ff83c..994714a3ce 100644 --- a/packages/cli/src/lib/config.ts +++ b/packages/cli/src/lib/config.ts @@ -96,11 +96,7 @@ export async function loadCliConfig(options: Options) { }); const frontendConfig = ConfigReader.fromConfigs(frontendAppConfigs); - const backendAppConfigs = schema.process(appConfigs, { - visibility: ['frontend', 'backend', 'secret'], - withFilteredKeys: options.withFilteredKeys, - withDeprecatedKeys: options.withDeprecatedKeys, - }); + const backendAppConfigs = schema.process(appConfigs); const backendConfig = ConfigReader.fromConfigs(backendAppConfigs); return { @@ -108,7 +104,6 @@ export async function loadCliConfig(options: Options) { appConfigs, frontendConfig, frontendAppConfigs, - backendAppConfigs, backendConfig, }; } catch (error) { diff --git a/packages/core-app-api/config.d.ts b/packages/core-app-api/config.d.ts index 6b707987e5..d88c818d11 100644 --- a/packages/core-app-api/config.d.ts +++ b/packages/core-app-api/config.d.ts @@ -65,26 +65,6 @@ export interface Config { }>; }>; }; - /** - * Running the frontend app with https - */ - https?: { - /** - * Parent object containing certificate and the private key - */ - certificate?: { - /** - * Https Certificate private key. Use $file to load in a file - * @visibility secret - */ - key?: string; - /** - * Https Certificate. Use $file to load in a file - * @visibility frontend - */ - cert?: string; - }; - }; }; /** From 6ec5064c94fd60df14d35df5f0620add0dda122e Mon Sep 17 00:00:00 2001 From: Luka Siric Date: Wed, 31 Aug 2022 12:27:18 +0200 Subject: [PATCH 5/7] resolved @benjdlambert comments Signed-off-by: Luka Siric --- .changeset/fast-paws-press.md | 1 - packages/cli/config.d.ts | 40 ----------------------------------- packages/cli/package.json | 23 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 41 deletions(-) delete mode 100644 packages/cli/config.d.ts diff --git a/.changeset/fast-paws-press.md b/.changeset/fast-paws-press.md index b9e1893963..8ddb0bc49e 100644 --- a/.changeset/fast-paws-press.md +++ b/.changeset/fast-paws-press.md @@ -1,6 +1,5 @@ --- '@backstage/cli': patch -'@backstage/core-app-api': minor --- Added support for custom certificate for webpack dev server. diff --git a/packages/cli/config.d.ts b/packages/cli/config.d.ts deleted file mode 100644 index 24cc60dac3..0000000000 --- a/packages/cli/config.d.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2022 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -export interface Config { - app: { - /** - * Running the frontend app with https - */ - https?: { - /** - * Parent object containing certificate and the private key - */ - certificate?: { - /** - * Https Certificate private key. Use $file to load in a file - * @visibility secret - */ - key: string; - /** - * Https Certificate. Use $file to load in a file - * @visibility secret - */ - cert: string; - }; - }; - }; -} diff --git a/packages/cli/package.json b/packages/cli/package.json index 27b540bff6..a4162c5e80 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -248,6 +248,29 @@ "description": "The port that the frontend should be bound to. Only used for local development." } } + }, + "https": { + "type": "object", + "description": "Running the frontend app with https", + "properties": { + "certificate": { + "type": "object", + "description": "Parent object containing certificate and the private key", + "required": ["key", "cert"], + "properties" : { + "key": { + "type" : "string", + "visibility": "secret", + "description": "Https Certificate private key. Use $file to load in a file" + }, + "cert": { + "type" : "string", + "visibility": "secret", + "description": "Https Certificate. Use $file to load in a file" + } + } + } + } } } } From c55bdf2ad9f34bba7751982e023e3eac55a09da2 Mon Sep 17 00:00:00 2001 From: Luka Siric Date: Wed, 31 Aug 2022 13:04:23 +0200 Subject: [PATCH 6/7] run prettier Signed-off-by: Luka Siric --- packages/cli/package.json | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index a4162c5e80..b978833d29 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -256,15 +256,18 @@ "certificate": { "type": "object", "description": "Parent object containing certificate and the private key", - "required": ["key", "cert"], - "properties" : { + "required": [ + "key", + "cert" + ], + "properties": { "key": { - "type" : "string", + "type": "string", "visibility": "secret", "description": "Https Certificate private key. Use $file to load in a file" }, "cert": { - "type" : "string", + "type": "string", "visibility": "secret", "description": "Https Certificate. Use $file to load in a file" } From 3a446f905c7af629c42d54489b8f7689b764e665 Mon Sep 17 00:00:00 2001 From: Luka Siric Date: Wed, 31 Aug 2022 16:55:08 +0200 Subject: [PATCH 7/7] modified https setting description in package.json Signed-off-by: Luka Siric --- packages/cli/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/package.json b/packages/cli/package.json index b978833d29..01e92c89d9 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -251,7 +251,7 @@ }, "https": { "type": "object", - "description": "Running the frontend app with https", + "description": "Only used for local development. The https object is passed to webpack in order to enable using https on localhost.", "properties": { "certificate": { "type": "object",