Fix exec not working for another region (#10539)

This conditionally includes a region query parameter when
opening the exec socket.
This commit is contained in:
Georges-Etienne Legendre 2021-05-13 10:14:16 -04:00 committed by GitHub
parent d161d79b67
commit 5ad8c8136a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -1,8 +1,11 @@
import Service from '@ember/service';
import config from 'nomad-ui/config/environment';
import { getOwner } from '@ember/application';
import { inject as service } from '@ember/service';
export default class SocketsService extends Service {
@service system;
getTaskStateSocket(taskState, command) {
const mirageEnabled =
config.environment !== 'production' &&
@ -27,10 +30,12 @@ export default class SocketsService extends Service {
const applicationAdapter = getOwner(this).lookup('adapter:application');
const prefix = `${applicationAdapter.host ||
window.location.host}/${applicationAdapter.urlPrefix()}`;
const region = this.system.activeRegion;
return new WebSocket(
`${protocol}//${prefix}/client/allocation/${taskState.allocation.id}` +
`/exec?task=${taskState.name}&tty=true&ws_handshake=true` +
(region ? `&region=${region}` : '') +
`&command=${encodeURIComponent(`["${command}"]`)}`
);
}