Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions code/core/src/bin/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ command('dev')
.option('--smoke-test', 'Exit after successful start')
.option('--ci', "CI mode (skip interactive prompts, don't open browser)")
.option('--no-open', 'Do not open Storybook automatically in the browser')
.option('--open-url <url>', 'Open a custom URL instead of the default local address')
.option('--quiet', 'Suppress verbose build output')
.option('--no-version-updates', 'Suppress update check', true)
.option('--debug-webpack', 'Display final webpack configurations for debugging purposes')
Expand Down Expand Up @@ -134,6 +135,10 @@ command('dev')
ci: 'CI',
});

if (!options.openUrl && process.env.STORYBOOK_OPEN_URL) {
options.openUrl = process.env.STORYBOOK_OPEN_URL;
}

if (parseInt(`${options.port}`, 10)) {
options.port = parseInt(`${options.port}`, 10);
}
Expand Down
12 changes: 9 additions & 3 deletions code/core/src/core-server/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,15 @@ export async function storybookDevServer(
const [indexGenerator] = await Promise.all([storyIndexGeneratorPromise, listening]);

if (indexGenerator && !options.ci && !options.smokeTest && options.open) {
const url = options.host ? options.networkAddress : options.localAddress;
openInBrowser(options.previewOnly ? `${url}iframe.html?navigator=true` : url!).catch(() => {
// the browser window could not be opened, this is non-critical, we just ignore the error
const defaultUrl = options.host ? options.networkAddress : options.localAddress;
const url =
options.openUrl ||
(options.previewOnly ? `${defaultUrl}iframe.html?navigator=true` : defaultUrl!);
// the browser window could not be opened, this is non-critical, we just ignore the error
openInBrowser(url).catch((err: Error) => {
if (options.openUrl) {
logger.warn(`Failed to open custom URL: ${url}\n ${err.message}`);
}
});
}
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions code/core/src/types/modules/core-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export interface CLIOptions extends CLIBaseOptions {
smokeTest?: boolean;
managerCache?: boolean;
open?: boolean;
openUrl?: string;
ci?: boolean;
versionUpdates?: boolean;
docs?: boolean;
Expand Down
1 change: 1 addition & 0 deletions docs/api/cli-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Options include:
| `--smoke-test` | Exit after successful start.<br />`storybook dev --smoke-test` |
| `--ci` | CI mode (skip interactive prompts, don't open browser).<br />`storybook dev --ci` |
| `--no-open` | Do not open Storybook automatically in the browser.<br />`storybook dev --no-open` |
| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix sentence fragment in option description.

Line 56 has a fragment: “Can also be set via...”. Make it a complete sentence for docs clarity.

✏️ Suggested edit
-| `--open-url <url>`              | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
+| `--open-url <url>`              | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. It can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
| `--open-url <url>` | Open a custom URL instead of the default local address. Useful when running a local HTTPS reverse proxy. It can also be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes precedence). Note: `--no-open` disables opening entirely and overrides both `--open-url` and the environment variable.<br />`storybook dev --open-url https://myapp.localhost` |
🧰 Tools
🪛 LanguageTool

[style] ~56-~56: To form a complete sentence, be sure to include a subject.
Context: ...en running a local HTTPS reverse proxy. Can also be set via the `STORYBOOK_OPEN_URL...

(MISSING_IT_THERE)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/api/cli-options.mdx` at line 56, The option description for `--open-url
<url>` contains a sentence fragment; revise the text so the fragment "Can also
be set via the `STORYBOOK_OPEN_URL` environment variable (CLI flag takes
precedence)." is a full sentence — e.g., change it to "It can also be set via
the `STORYBOOK_OPEN_URL` environment variable (the CLI flag takes precedence)."
Ensure the note about `--no-open` remains unchanged and keep references to
`--open-url <url>` and `STORYBOOK_OPEN_URL` intact.

| `--quiet` | Suppress verbose build output.<br />`storybook dev --quiet` |
| `--debug` | Outputs more logs in the CLI to assist debugging.<br />`storybook dev --debug` |
| `--debug-webpack` | Display final webpack configurations for debugging purposes.<br />`storybook dev --debug-webpack` |
Expand Down
Loading