Outlook_Addin_LLM/node_modules/@microsoft/dev-tunnels-contracts/tunnelEndpointStatics.js

49 lines
2.0 KiB
JavaScript

"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPortSshCommand = exports.getPortUri = void 0;
const tunnelEndpoint_1 = require("./tunnelEndpoint");
/**
* Gets a URI where a web client can connect to a tunnel port.
*
* Requests to the URI may result in HTTP 307 redirections, so the client may need to
* follow the redirection in order to connect to the port.
*
* If the port is not currently shared via the tunnel, or if a host is not currently
* connected to the tunnel, then requests to the port URI may result in a 502 Bad Gateway
* response.
*
* @param endpoint The tunnel endpoint containing connection information.
* @param portNumber The port number to connect to; the port is assumed to be
* separately shared by a tunnel host.
* @returns URI for the requested port, or `undefined` if the endpoint does not support
* web client connections.
*/
function getPortUri(endpoint, portNumber) {
if (!endpoint) {
throw new TypeError('A tunnel endpoint is required.');
}
if (typeof portNumber !== 'number' && !endpoint.tunnelUri) {
return endpoint.tunnelUri;
}
if (typeof portNumber !== 'number' || !endpoint.portUriFormat) {
return undefined;
}
return endpoint.portUriFormat.replace(tunnelEndpoint_1.portToken, portNumber.toString());
}
exports.getPortUri = getPortUri;
function getPortSshCommand(endpoint, portNumber) {
if (!endpoint) {
throw new TypeError('A tunnel endpoint is required.');
}
if (typeof portNumber !== 'number' && !endpoint.tunnelSshCommand) {
return endpoint.tunnelSshCommand;
}
if (typeof portNumber !== 'number' || !endpoint.portSshCommandFormat) {
return undefined;
}
return endpoint.portSshCommandFormat.replace(tunnelEndpoint_1.portToken, portNumber.toString());
}
exports.getPortSshCommand = getPortSshCommand;
//# sourceMappingURL=tunnelEndpointStatics.js.map