Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ javaTypes.js
tomcatManager.js
apimlStorage.js
pluginStorage.js
proxy.js

# This program and the accompanying materials are
# made available under the terms of the Eclipse Public License v2.0 which accompanies
Expand Down
34 changes: 16 additions & 18 deletions lib/proxy.js → lib/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
*
*/
'use strict';
const http = require('http');
const https = require('https');
const express = require('express');
const util = require('./util');
const unpconst = require('./unp-constants');
const WebSocket = require('ws');
const net = require('net');
import * as http from 'node:http';
import * as https from 'node:https';
import * as express from 'express';
import * as util from './util';
import * as unpconst from './unp-constants';
import * as WebSocket from 'ws';
import * as net from 'node:net';
import * as url from 'node:url';

const proxyLog = util.loggers.proxyLogger;
const RECONNECT_DELAY = 5000;
const DEFAULT_HANDSHAKE_TIMEOUT = 30000;

function convertOptions(request, realHost, realPort, urlPrefix, requestProcessingOptions) {
var options = {};
function convertOptions(request, realHost: string, realPort: number, urlPrefix: string, requestProcessingOptions?) {
let options: any = {};
proxyLog.debug("ZWED0166I", request.headers.host); //proxyLog.debug("request host " + request.headers.host);

let ipFamily = 4;
Expand Down Expand Up @@ -72,7 +73,7 @@ function convertOptions(request, realHost, realPort, urlPrefix, requestProcessin
return options;
}

function makeSimpleProxy(host, port, options, pluginID, serviceName) {
function makeSimpleProxy(host: string, port: number, options, pluginID: string, serviceName: string) {
if (!(host && port)) {
throw new Error(`ZWED0047E - Proxy (${pluginID}:${serviceName}) setup failed.\n`
+ `Host & Port for proxy destination are required but were missing.\n`
Expand Down Expand Up @@ -151,7 +152,7 @@ function makeSimpleProxy(host, port, options, pluginID, serviceName) {
}
}

function makeWsProxy(host, port, urlPrefix, options) {
function makeWsProxy(host: string, port: number, urlPrefix: string, options) {
// copied and pasted with only minimal fixes to formatting
var toString = function() {
return '[Proxy URL: '+urlPrefix+']';
Expand Down Expand Up @@ -329,7 +330,7 @@ function makeWsProxy(host, port, urlPrefix, options) {
};
};

function checkProxiedHost(host, port, handshakeTimeout) {
function checkProxiedHost(host: string, port: number, handshakeTimeout?: number) {
const client = new net.Socket();
let timeLeft = handshakeTimeout ? handshakeTimeout : DEFAULT_HANDSHAKE_TIMEOUT;
return new Promise((resolve, reject) => {
Expand All @@ -340,10 +341,10 @@ function checkProxiedHost(host, port, handshakeTimeout) {

client.once("connect", () => {
client.destroy();
resolve();
resolve(null);
});

client.on('error', (e) => {
client.on('error', (e: any) => {
if (timeLeft <= 0) {
proxyLog.warn(`ZWED0045W`, host, port); //proxyLog.warn(`Failed to reach the auth services host for address ${host}:${port}`);
if (host === '127.0.0.1') {
Expand All @@ -364,10 +365,7 @@ function checkProxiedHost(host, port, handshakeTimeout) {
});
}

exports.makeSimpleProxy = makeSimpleProxy;
exports.makeWsProxy = makeWsProxy;
exports.checkProxiedHost = checkProxiedHost;

export = { makeSimpleProxy, makeWsProxy, checkProxiedHost };

/*
This program and the accompanying materials are
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
"exclude": ["lib/*.js"],
"compilerOptions": {
"sourceMap": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
"target": "es2021",
"types": [
"node",
"express"
],
"lib": ["es5", "es6", "DOM"]
"lib": ["DOM", "es2021"]
}
}
Loading