如何在应用代码中以编程方式获取stroybook启动的本地服务的地址?
How to get the address of the local service started by stroybook programmatically in the application code?
当运行 below npm script时,它会启动一个地址为http://localhost:6006
的本地服务器。
"storybook": "start-storybook -p 6006 -s public",
我想在 xxx.stories.tsx
文件顶部的应用程序代码中获取此地址,我该怎么做?也许我可以从某些 environment variable 中获取服务器地址,例如 STORYBOOK_SERVER_ADDRESS
。但我不确定。
import React from 'react';
import { Story, Meta } from '@storybook/react/types-6-0';
import { Article, ArticleProps } from '../components/Article';
import faker from 'faker';
export default {
title: 'Example/Article',
component: Article,
} as Meta;
console.log('get local server address here');
包版本:
"@storybook/addon-actions": "^6.1.10",
"@storybook/addon-essentials": "^6.1.10",
"@storybook/addon-links": "^6.1.10",
"@storybook/node-logger": "^6.1.10",
"@storybook/preset-create-react-app": "^3.1.5",
"@storybook/react": "^6.1.10",
要获得完整的 URL 地址,请使用:
window.location.href
要获取主机名,请使用:
window.location.hostname
当运行 below npm script时,它会启动一个地址为http://localhost:6006
的本地服务器。
"storybook": "start-storybook -p 6006 -s public",
我想在 xxx.stories.tsx
文件顶部的应用程序代码中获取此地址,我该怎么做?也许我可以从某些 environment variable 中获取服务器地址,例如 STORYBOOK_SERVER_ADDRESS
。但我不确定。
import React from 'react';
import { Story, Meta } from '@storybook/react/types-6-0';
import { Article, ArticleProps } from '../components/Article';
import faker from 'faker';
export default {
title: 'Example/Article',
component: Article,
} as Meta;
console.log('get local server address here');
包版本:
"@storybook/addon-actions": "^6.1.10",
"@storybook/addon-essentials": "^6.1.10",
"@storybook/addon-links": "^6.1.10",
"@storybook/node-logger": "^6.1.10",
"@storybook/preset-create-react-app": "^3.1.5",
"@storybook/react": "^6.1.10",
要获得完整的 URL 地址,请使用:
window.location.href
要获取主机名,请使用:
window.location.hostname