Merge pull request #15559 from agentbellnorm/provide-embedded-app-bundle
[TechDocs] Allow user to provide embedded app bundle and specify port
This commit is contained in:
@@ -18,6 +18,7 @@ import { Command } from 'commander';
|
||||
import { TechdocsGenerator } from '@backstage/plugin-techdocs-node';
|
||||
|
||||
const defaultDockerImage = TechdocsGenerator.defaultDockerImage;
|
||||
const defaultPreviewAppPort = '3000';
|
||||
|
||||
export function registerCommands(program: Command) {
|
||||
program
|
||||
@@ -251,6 +252,25 @@ export function registerCommands(program: Command) {
|
||||
)
|
||||
.option('--mkdocs-port <PORT>', 'Port for MkDocs server to use', '8000')
|
||||
.option('-v --verbose', 'Enable verbose output.', false)
|
||||
.option(
|
||||
'--preview-app-bundle-path <PATH_TO_BUNDLE>',
|
||||
'Preview documentation using another web app',
|
||||
)
|
||||
.option(
|
||||
'--preview-app-port <PORT>',
|
||||
'Port for the preview app to be served on',
|
||||
defaultPreviewAppPort,
|
||||
)
|
||||
.hook('preAction', command => {
|
||||
if (
|
||||
command.opts().previewAppPort !== defaultPreviewAppPort &&
|
||||
!command.opts().previewAppBundlePath
|
||||
) {
|
||||
command.error(
|
||||
'--preview-app-port can only be used together with --preview-app-bundle-path',
|
||||
);
|
||||
}
|
||||
})
|
||||
.action(lazy(() => import('./serve/serve').then(m => m.default)));
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,10 @@ function findPreviewBundlePath(): string {
|
||||
}
|
||||
}
|
||||
|
||||
function getPreviewAppPath(opts: OptionValues): string {
|
||||
return opts.previewAppBundlePath ?? findPreviewBundlePath();
|
||||
}
|
||||
|
||||
export default async function serve(opts: OptionValues) {
|
||||
const logger = createLogger({ verbose: opts.verbose });
|
||||
|
||||
@@ -52,10 +56,6 @@ export default async function serve(opts: OptionValues) {
|
||||
? true
|
||||
: false;
|
||||
|
||||
// TODO: Backstage app port should also be configurable as a CLI option. However, since we bundle
|
||||
// a backstage app, we define app.baseUrl in the app-config.yaml.
|
||||
// Hence, it is complicated to make this configurable.
|
||||
const backstagePort = 3000;
|
||||
const backstageBackendPort = 7007;
|
||||
|
||||
const mkdocsDockerAddr = `http://0.0.0.0:${opts.mkdocsPort}`;
|
||||
@@ -115,9 +115,10 @@ export default async function serve(opts: OptionValues) {
|
||||
);
|
||||
}
|
||||
|
||||
const port = isDevMode ? backstageBackendPort : backstagePort;
|
||||
const port = isDevMode ? backstageBackendPort : opts.previewAppPort;
|
||||
const previewAppPath = getPreviewAppPath(opts);
|
||||
const httpServer = new HTTPServer(
|
||||
findPreviewBundlePath(),
|
||||
previewAppPath,
|
||||
port,
|
||||
opts.mkdocsPort,
|
||||
opts.verbose,
|
||||
|
||||
Reference in New Issue
Block a user