-
Notifications
You must be signed in to change notification settings - Fork 936
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
Added support for non root (home) deployment of bit-server #4923 #4958
Open
pgangwani
wants to merge
17
commits into
teambit:master
Choose a base branch
from
pgangwani:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ad57a3e
feat: Adding support for the non root bit-server deployment
c86e4a9
Merge branch 'master' of https://github.com/teambit/bit
0a739a4
feat: would like to see here
66e7e7d
refactor: reverting unrelated changes though it came from linter
9eef500
refactor: reverting unrelated changes again
48fcec4
fix: encorporate review comments
51a664d
fix: encorporate review comments
d7148bd
Merge branch 'master' into master
KutnerUri b671407
react-router basename
KutnerUri f566e08
gql basename
KutnerUri 8bd9264
use createHref in preview routes
KutnerUri 2fb569c
refactor gql endpoints
KutnerUri d860f0a
forward gql endpoints to preview
KutnerUri 9a534c5
Merge branch 'master' into master
KutnerUri 11a8fb5
forward ui config during preview
KutnerUri e055759
rename publicPath to be urlBasename
KutnerUri 25dd1a9
add basename to graphql endpoint
KutnerUri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export type GqlConfig = { | ||
/** gql pathname | ||
* @default '/graphql' | ||
*/ | ||
endpoint: string; | ||
/** graphql pathname during SSR | ||
* @default '/graphql | ||
*/ | ||
ssrEndpoint?: string; | ||
/** gql pathname for subscriptions | ||
* @default '/subscriptions' | ||
*/ | ||
subscriptionEndpoint?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import { PreviewRuntime } from '@teambit/preview'; | ||
import PreviewAspect, { PreviewPreview, PreviewRuntime } from '@teambit/preview'; | ||
|
||
import { GraphqlAspect } from './graphql.aspect'; | ||
import { GraphqlUI } from './graphql.ui.runtime'; | ||
|
||
GraphqlUI.runtime = PreviewRuntime; | ||
GraphqlAspect.addRuntime(GraphqlUI); | ||
export class GraphqlPreview extends GraphqlUI { | ||
static runtime = PreviewRuntime; | ||
static slots = GraphqlUI.slots; | ||
static dependencies = [PreviewAspect]; | ||
} | ||
|
||
// @ts-ignore | ||
GraphqlPreview.provider = ([previewPreview]: [PreviewPreview]) => { | ||
const graphqlPreview = new GraphqlPreview(); | ||
|
||
previewPreview.registerRenderContext(() => graphqlPreview.getConfig()); | ||
|
||
return graphqlPreview; | ||
}; | ||
|
||
GraphqlAspect.addRuntime(GraphqlPreview); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import React, { ReactNode } from 'react'; | ||
import urlJoin from 'url-join'; | ||
import { UIRuntime } from '@teambit/ui'; | ||
import type { Aspect } from '@teambit/harmony'; | ||
|
||
import { InMemoryCache, ApolloClient, ApolloLink, HttpLink, createHttpLink } from '@apollo/client'; | ||
import type { NormalizedCacheObject } from '@apollo/client'; | ||
|
@@ -13,6 +15,7 @@ import { GraphQLProvider } from './graphql-provider'; | |
import { GraphqlAspect } from './graphql.aspect'; | ||
import { GraphqlRenderLifecycle } from './render-lifecycle'; | ||
import { logError } from './logging'; | ||
import { GqlConfig } from './gql-config'; | ||
|
||
/** | ||
* Type of gql client. | ||
|
@@ -57,6 +60,19 @@ export class GraphqlUI { | |
return client; | ||
} | ||
|
||
getConfig = (): GqlConfig => { | ||
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. dynamic gql endpoints, based on configuration |
||
return { | ||
endpoint: urlJoin(this.baseName, 'graphql'), | ||
ssrEndpoint: urlJoin(this.baseName, 'graphql'), | ||
subscriptionEndpoint: urlJoin(this.baseName, 'subscriptions'), | ||
}; | ||
}; | ||
|
||
private baseName = '/'; | ||
setBasename(value: string) { | ||
this.baseName = value; | ||
} | ||
|
||
private createCache({ state }: { state?: NormalizedCacheObject } = {}) { | ||
const cache = new InMemoryCache(); | ||
|
||
|
@@ -90,7 +106,7 @@ export class GraphqlUI { | |
renderHooks = new GraphqlRenderLifecycle(this); | ||
|
||
static runtime = UIRuntime; | ||
static dependencies = []; | ||
static dependencies: Aspect[] = []; | ||
static slots = []; | ||
|
||
static async provider() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { ComponentPreview } from './preview'; | ||
export { toPreviewUrl, toPreviewServer, toPreviewHash } from './urls'; | ||
export { usePreviewUrl, toPreviewUrl, toPreviewServer, toPreviewHash } from './urls'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,13 @@ export type UIConfig = { | |
*/ | ||
publicDir: string; | ||
|
||
/** the url to display when server is listening. Note that bit does not provide proxying to this url */ | ||
/** | ||
* 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', | ||
}; | ||
|
@@ -535,7 +550,7 @@ export class UiMain { | |
|
||
static async provider( | ||
[pubsub, cli, graphql, express, componentExtension, cache, loggerMain]: UIDeps, | ||
config, | ||
config: UIConfig, | ||
[uiRootSlot, preStartSlot, onStartSlot, publicDirOverwriteSlot, buildMethodOverwriteSlot, proxyGetterSlot]: [ | ||
UIRootRegistry, | ||
PreStartSlot, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
forward gql config to preview