-
Notifications
You must be signed in to change notification settings - Fork 941
Added support for non root (home) deployment of bit-server #4923 #4958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
ad57a3e
c86e4a9
0a739a4
66e7e7d
9eef500
48fcec4
51a664d
d7148bd
b671407
f566e08
8bd9264
2fb569c
d860f0a
9a534c5
11a8fb5
e055759
25dd1a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ export function toPreviewServer(component: ComponentModel) { | |
|
||
// fallback url for all components. Includes versions support | ||
// for example - "/api/teambit.base-ui/input/[email protected]/~aspect/preview/" | ||
const defaultServerUrl = `/api/${component.id.toString()}/~aspect/preview/`; | ||
const defaultServerUrl = `/bit-dev/api/${component.id.toString()}/~aspect/preview/`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to pass basename (from where..?) as prop. Where to get the basename prop though? worse case we can set a global react-context from the UI aspect, something like: const { basename, apiPath } = useContext(???);
const defaultServerUrl = `${apiPath}/${component.id.toString()}/~aspect/preview/`; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking of adding basename to our internal routing system, as part of the changes I'm going to do to It would be more elegant. Then again, I'm not sure it will work here, because |
||
|
||
return explicitUrl || /* envBasedUrl || */ defaultServerUrl; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ type RouterContextProps = { | |
routing?: Routing; | ||
children: ReactNode; | ||
location?: string; | ||
basename?: string; | ||
}; | ||
|
||
type RootRouteProps = { | ||
|
@@ -23,10 +24,16 @@ type RootRouteProps = { | |
/** | ||
* Setup context needed for routing. | ||
*/ | ||
export function RouteContext({ reactRouterUi, routing = Routing.url, children, location }: RouterContextProps) { | ||
export function RouteContext({ | ||
reactRouterUi, | ||
routing = Routing.url, | ||
children, | ||
location, | ||
basename = '/bit-dev/', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default should be undefined (if possible), or the "bit-dev" should come from the UI aspect |
||
}: RouterContextProps) { | ||
return ( | ||
// {/* set up the virtual router (browser, inMemory, etc) */} | ||
<Router type={routing} location={location}> | ||
<Router type={routing} location={location} basename={basename}> | ||
{/* injects History object back to reactRouterUi */} | ||
<HistoryGetter onRouterChange={reactRouterUi.setRouter} /> | ||
{/* injects react-router Link into context */} | ||
|
@@ -43,21 +50,35 @@ export function RootRoute({ rootRoutes, routeSlot }: RootRouteProps) { | |
} | ||
|
||
/** provides the router engine (browser, inMemory, etc) */ | ||
function Router({ type, children, location }: { type: Routing; children: ReactNode; location?: string }) { | ||
function Router({ | ||
type, | ||
children, | ||
location, | ||
basename, | ||
}: { | ||
type: Routing; | ||
children: ReactNode; | ||
location?: string; | ||
basename?: string; | ||
}) { | ||
switch (type) { | ||
case Routing.static: | ||
return <StaticRouter location={location}>{children}</StaticRouter>; | ||
return ( | ||
<StaticRouter basename={basename} location={location}> | ||
{children} | ||
</StaticRouter> | ||
); | ||
case Routing.inMemory: | ||
return ( | ||
<MemoryRouter initialEntries={[location || '/']} initialIndex={1}> | ||
{children} | ||
</MemoryRouter> | ||
); | ||
case Routing.hash: | ||
return <HashRouter>{children}</HashRouter>; | ||
return <HashRouter basename={basename}>{children}</HashRouter>; | ||
case Routing.url: | ||
default: | ||
return <BrowserRouter>{children}</BrowserRouter>; | ||
return <BrowserRouter basename={basename}>{children}</BrowserRouter>; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,12 @@ export type UIConfig = { | |
*/ | ||
publicDir: string; | ||
|
||
/** | ||
* set `publicPath` value for webpack.config to override | ||
* in case server is not accessed using root route. | ||
*/ | ||
publicPath: string; | ||
|
||
/** the url to display when server is listening. Note that bit does not provide proxying to this url */ | ||
publicUrl?: string; | ||
}; | ||
|
@@ -216,7 +222,13 @@ export class UiMain { | |
const ssr = uiRoot.buildOptions?.ssr || false; | ||
const mainEntry = await this.generateRoot(await uiRoot.resolveAspects(UIRuntime.name), name); | ||
|
||
const browserConfig = createWebpackConfig(uiRoot.path, [mainEntry], uiRoot.name, await this.publicDir(uiRoot)); | ||
const browserConfig = createWebpackConfig( | ||
uiRoot.path, | ||
[mainEntry], | ||
uiRoot.name, | ||
await this.publicDir(uiRoot), | ||
this.config.publicPath | ||
); | ||
const ssrConfig = ssr && createSsrWebpackConfig(uiRoot.path, [mainEntry], await this.publicDir(uiRoot)); | ||
|
||
const config = [browserConfig, ssrConfig].filter((x) => !!x) as webpack.Configuration[]; | ||
|
@@ -490,7 +502,8 @@ export class UiMain { | |
uiRoot.path, | ||
[await this.generateRoot(await uiRoot.resolveAspects(UIRuntime.name), name)], | ||
uiRoot.name, | ||
await this.publicDir(uiRoot) | ||
await this.publicDir(uiRoot), | ||
this.config.publicPath | ||
); | ||
if (config.output?.path && fs.pathExistsSync(config.output.path)) return; | ||
const hash = await this.buildUiHash(uiRoot); | ||
|
@@ -509,6 +522,8 @@ export class UiMain { | |
|
||
static defaultConfig: UIConfig = { | ||
publicDir: 'public/bit', | ||
// Changing to relative path which should work in all cases | ||
publicPath: process.env.ASSET_PATH || './', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooh this looks interesting, how does it work |
||
portRange: [3000, 3100], | ||
host: 'localhost', | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to pass basename from graphql/ui aspect