forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: SuZhoue-Joe <[email protected]> feat: optimize code Signed-off-by: SuZhoue-Joe <[email protected]> feat: remove useless change Signed-off-by: SuZhoue-Joe <[email protected]> feat: optimize url listener Signed-off-by: SuZhoue-Joe <[email protected]> feat: make formatUrlWithWorkspaceId extensible Signed-off-by: SuZhoue-Joe <[email protected]> feat: modify the async format to be sync function Signed-off-by: SuZhoue-Joe <[email protected]> feat: use path to maintain workspace info Signed-off-by: SuZhou-Joe <[email protected]> feat: optimize code Signed-off-by: SuZhou-Joe <[email protected]> feat: optimize code Signed-off-by: SuZhou-Joe <[email protected]> feat: optimize code Signed-off-by: SuZhou-Joe <[email protected]> feat: optimize code Signed-off-by: SuZhou-Joe <[email protected]> feat: optimize code Signed-off-by: SuZhou-Joe <[email protected]> feat: optimize code Signed-off-by: SuZhou-Joe <[email protected]> feat: format Signed-off-by: SuZhou-Joe <[email protected]> feat: format Signed-off-by: SuZhou-Joe <[email protected]> feat: format Signed-off-by: SuZhou-Joe <[email protected]> feat: format Signed-off-by: SuZhou-Joe <[email protected]> feat: format Signed-off-by: SuZhou-Joe <[email protected]> feat: format Signed-off-by: SuZhou-Joe <[email protected]> feat: format Signed-off-by: SuZhou-Joe <[email protected]>
- Loading branch information
1 parent
99ae1a5
commit 86ac4a8
Showing
8 changed files
with
112 additions
and
9 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const getWorkspaceIdFromUrl = (url: string): string => { | ||
const regexp = /\/w\/([^\/]*)/; | ||
const urlObject = new URL(url); | ||
const matchedResult = urlObject.pathname.match(regexp); | ||
if (matchedResult) { | ||
return matchedResult[1]; | ||
} | ||
|
||
return ''; | ||
}; |
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,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { URL } from 'node:url'; | ||
import { HttpServiceSetup, Plugin } from 'opensearch-dashboards/server'; | ||
|
||
export interface WorkspacesSetupDeps { | ||
http: HttpServiceSetup; | ||
} | ||
|
||
export class WorkspacesService implements Plugin<{}, {}> { | ||
private proxyWorkspaceTrafficToRealHandler(setupDeps: WorkspacesSetupDeps) { | ||
/** | ||
* Proxy all {basePath}/w/{workspaceId}{osdPath*} paths to | ||
* {basePath}{osdPath*} | ||
*/ | ||
setupDeps.http.registerOnPreRouting((request, response, toolkit) => { | ||
const regexp = /\/w\/([^\/]*)/; | ||
const matchedResult = request.url.pathname.match(regexp); | ||
if (matchedResult) { | ||
const requestUrl = new URL(request.url.toString()); | ||
requestUrl.pathname = requestUrl.pathname.replace(regexp, ''); | ||
return toolkit.rewriteUrl(requestUrl.toString()); | ||
} | ||
return toolkit.next(); | ||
}); | ||
} | ||
|
||
public async setup(setupDeps: WorkspacesSetupDeps) { | ||
this.proxyWorkspaceTrafficToRealHandler(setupDeps); | ||
|
||
return {}; | ||
} | ||
|
||
public async start(deps: {}) { | ||
return {}; | ||
} | ||
|
||
public async stop() {} | ||
} |