-
Notifications
You must be signed in to change notification settings - Fork 111
Fix webview after changes in upstream. #563
Changes from all commits
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 |
---|---|---|
|
@@ -76,7 +76,8 @@ if [ "${NOCDN}" == "true" ]; then | |
fi | ||
shopt -u nocasematch | ||
|
||
# run che | ||
# run Che Theia | ||
export THEIA_WEBVIEW_EXTERNAL_ENDPOINT=$(node get-webview-route.js) | ||
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. question: we don't have the endpoint as environment variable ? 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 mean, che-server is not providing that information to containers through env vars ? 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. No, we don't have external route in env vars. |
||
node src-gen/backend/main.js /projects --hostname=0.0.0.0 --port=${THEIA_PORT} & | ||
|
||
PID=$! | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
**********************************************************************/ | ||
|
||
const fs = require('fs'); | ||
const workspaceClient = require('@eclipse-che/workspace-client'); | ||
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. where does it find this dependency ? 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. It gets the dependency from Che Theia node modules. 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. In the dockerfile we copy script to the /home/theia, where is located node_modules |
||
|
||
// Assume that self-signed certificate is located by the following path | ||
const SS_CRT_PATH = '/tmp/che/secret/ca.crt'; | ||
|
||
// Configure workspace API client | ||
const restAPIConfig = { | ||
baseUrl: process.env.CHE_API | ||
}; | ||
|
||
const token = process.env.CHE_MACHINE_TOKEN; | ||
if (token) { | ||
restAPIConfig.headers = {}; | ||
restAPIConfig.headers['Authorization'] = 'Bearer ' + token; | ||
} | ||
|
||
if (fs.existsSync(SS_CRT_PATH)) { | ||
restAPIConfig.ssCrtPath = SS_CRT_PATH; | ||
} | ||
|
||
// Create rest API workspace client | ||
const restApiClient = workspaceClient.default.getRestApi(restAPIConfig); | ||
|
||
// Search for IDE route | ||
function getIdeRoute() { | ||
return new Promise((resolve, reject) => { | ||
restApiClient.getById(process.env.CHE_WORKSPACE_ID).then(workspace => { | ||
const containers = workspace.runtime.machines; | ||
Object.keys(containers).forEach(containerName => { | ||
const container = containers[containerName]; | ||
const servers = container['servers']; | ||
if (servers) { | ||
const ideServerName = Object.keys(servers).find(serverName => servers[serverName].attributes && servers[serverName].attributes['type'] === 'ide'); | ||
if (ideServerName) { | ||
resolve(servers[ideServerName].url); | ||
} | ||
} | ||
}); | ||
reject('Server with type "ide" not found.'); | ||
}).catch(error => { | ||
reject(error); | ||
}); | ||
}); | ||
} | ||
|
||
getIdeRoute().then(ideRoute => { | ||
if (!ideRoute) { | ||
throw new Error('Failed to get ide route.'); | ||
} | ||
|
||
// Remove trailing slash if any | ||
if (ideRoute.endsWith('/')) { | ||
ideRoute = ideRoute.substring(0, ideRoute.length - 1); | ||
} | ||
// Remove protocol | ||
const webviewDomain = ideRoute.replace(/^https?:\/\//, ''); | ||
// Return result to shell by writing into stdout | ||
process.stdout.write(webviewDomain); | ||
}).catch(error => { | ||
console.error('Unable to get IDE route. Webviews might not work. Cause:', error); | ||
// Just exit this script without returning a value to the shell. | ||
}); |
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.
Should it be possible (maybe later) to use a runtime information instead of using environment variable.
Explanation: Here we're using a shell script before running the theia process in the container (by setting environment variable)
I think it would be cleaner if we bring a hook/extension point of theia at runtime by updating the setting on the fly. So no need to use separate script and fix env variable. It's when theia webview will resolve stuff that it will deal with che-theia code
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.
like to override this class: https://github.com/eclipse-theia/theia/blob/fc49b2c3b8a690ba5b94e1fd48cf17469b51057d/packages/plugin-ext/src/main/browser/webview/webview-environment.ts#L35
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.
Yes, I think we can do it in runtime.
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.
I think we should try, but as for now I would like to merge current PR as it is tested and fixes (for https case) blocker issue.
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.
yes this is why I said later