Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .github/scripts/before-beta-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const PACKAGE_NAME = pkgJson.name;
const VERSION = pkgJson.version;

const nextVersion = getNextVersion(VERSION);
// eslint-disable-next-line no-console
console.log(`before-deploy: Setting version to ${nextVersion}`);
pkgJson.version = nextVersion;

Expand All @@ -21,6 +22,7 @@ function getNextVersion(version) {
const versions = JSON.parse(versionString);

if (versions.some((v) => v === VERSION)) {
// eslint-disable-next-line no-console
console.error(`before-deploy: A release with version ${VERSION} already exists. Please increment version accordingly.`);
process.exit(1);
}
Expand Down
4 changes: 3 additions & 1 deletion examples/apify_proxy_tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ const { createTunnel, closeTunnel, redactUrl } = require('proxy-chain');
// The "verbose" option causes a lot of logging
const tunnelInfo = await createTunnel(PROXY_URL, TARGET_HOST, { port: 9999, verbose: true });

// eslint-disable-next-line no-console
console.log(`Tunnel to ${TARGET_HOST} via ${redactUrl(PROXY_URL)} established at ${tunnelInfo}...`);

// Here we assume por 443 from above, otherwise the service will not be accessible via HTTPS!
// eslint-disable-next-line no-console
console.log(`To test it, you can run: curl --verbose https://${tunnelInfo}`);

// Wait forever...
await new Promise(() => {});
await new Promise(() => { });

// Normally, you'd also want to close the tunnel and all open connections
await closeTunnel(tunnelInfo, true);
Expand Down
181 changes: 91 additions & 90 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,93 +1,94 @@
{
"name": "proxy-chain",
"version": "2.5.9",
"description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.",
"main": "dist/index.js",
"keywords": [
"proxy",
"squid",
"apify",
"tunnel",
"puppeteer"
],
"author": {
"name": "Apify Technologies",
"email": "[email protected]",
"url": "https://apify.com"
},
"contributors": [
"Jan Curn <[email protected]>"
],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/apify/proxy-chain"
},
"bugs": {
"url": "https://github.com/apify/proxy-chain/issues"
},
"homepage": "https://blog.apify.com/how-to-make-headless-chrome-and-puppeteer-use-a-proxy-server-with-authentication-249a21a79212",
"files": [
"dist"
],
"scripts": {
"build:watch": "tsc -w",
"build": "tsc",
"clean": "rimraf dist",
"prepublishOnly": "npm run build",
"local-proxy": "node ./dist/run_locally.js",
"test": "nyc cross-env NODE_OPTIONS=--insecure-http-parser mocha --bail",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"engines": {
"node": ">=14"
},
"devDependencies": {
"@apify/eslint-config": "^1.0.0",
"@apify/tsconfig": "^0.1.0",
"@types/jest": "^28.1.2",
"@types/node": "^18.8.3",
"basic-auth": "^2.0.1",
"basic-auth-parser": "^0.0.2",
"body-parser": "^1.19.0",
"chai": "^4.3.4",
"cross-env": "^7.0.3",
"eslint": "^9.18.0",
"express": "^4.17.1",
"faye-websocket": "^0.11.4",
"got-scraping": "^3.2.4-beta.0",
"isparta": "^4.1.1",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"portastic": "^1.0.1",
"proxy": "^1.0.2",
"puppeteer": "^19.6.3",
"request": "^2.88.2",
"rimraf": "^4.1.2",
"sinon": "^13.0.2",
"sinon-stub-promise": "^4.0.0",
"socksv5": "^0.0.6",
"through": "^2.3.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.3",
"typescript-eslint": "^8.20.0",
"underscore": "^1.13.1",
"ws": "^8.2.2"
},
"nyc": {
"reporter": [
"text",
"html",
"lcov"
"name": "proxy-chain",
"version": "2.5.9",
"description": "Node.js implementation of a proxy server (think Squid) with support for SSL, authentication, upstream proxy chaining, and protocol tunneling.",
"main": "dist/index.js",
"keywords": [
"proxy",
"squid",
"apify",
"tunnel",
"puppeteer"
],
"exclude": [
"**/test/**"
]
},
"dependencies": {
"socks": "^2.8.3",
"socks-proxy-agent": "^8.0.3",
"tslib": "^2.3.1"
}
"author": {
"name": "Apify Technologies",
"email": "[email protected]",
"url": "https://apify.com"
},
"contributors": [
"Jan Curn <[email protected]>"
],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/apify/proxy-chain"
},
"bugs": {
"url": "https://github.com/apify/proxy-chain/issues"
},
"homepage": "https://blog.apify.com/how-to-make-headless-chrome-and-puppeteer-use-a-proxy-server-with-authentication-249a21a79212",
"files": [
"dist"
],
"scripts": {
"build:watch": "tsc -w",
"build": "tsc",
"clean": "rimraf dist",
"prepublishOnly": "npm run build",
"local-proxy": "node ./dist/run_locally.js",
"test": "nyc cross-env NODE_OPTIONS=--insecure-http-parser mocha --bail",
"test:docker": "docker build --tag proxy-chain-tests --file test/Dockerfile . && docker run proxy-chain-tests",
"lint": "eslint .",
"lint:fix": "eslint . --fix"
},
"engines": {
"node": ">=14"
},
"devDependencies": {
"@apify/eslint-config": "^1.0.0",
"@apify/tsconfig": "^0.1.0",
"@types/jest": "^28.1.2",
"@types/node": "^18.8.3",
"basic-auth": "^2.0.1",
"basic-auth-parser": "^0.0.2",
"body-parser": "^1.19.0",
"chai": "^4.3.4",
"cross-env": "^7.0.3",
"eslint": "^9.18.0",
"express": "^4.17.1",
"faye-websocket": "^0.11.4",
"got-scraping": "^3.2.4-beta.0",
"isparta": "^4.1.1",
"mocha": "^10.0.0",
"nyc": "^15.1.0",
"portastic": "^1.0.1",
"proxy": "^1.0.2",
"puppeteer": "^19.6.3",
"request": "^2.88.2",
"rimraf": "^4.1.2",
"sinon": "^13.0.2",
"sinon-stub-promise": "^4.0.0",
"socksv5": "^0.0.6",
"through": "^2.3.8",
"ts-node": "^10.2.1",
"typescript": "^4.4.3",
"typescript-eslint": "^8.20.0",
"underscore": "^1.13.1",
"ws": "^8.2.2"
},
"nyc": {
"reporter": [
"text",
"html",
"lcov"
],
"exclude": [
"**/test/**"
]
},
"dependencies": {
"socks": "^2.8.3",
"socks-proxy-agent": "^8.0.3",
"tslib": "^2.3.1"
}
}
1 change: 1 addition & 0 deletions src/tcp_tunnel_tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function createTunnel(
const server: net.Server & { log?: (...args: unknown[]) => void } = net.createServer();

const log = (...args: unknown[]): void => {
// eslint-disable-next-line no-console
if (verbose) console.log(...args);
};

Expand Down
33 changes: 17 additions & 16 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# You can use this Dockerfile to run the tests on Linux,
# since the sockets behave a little differently there than on Mac
#
# Usage:
# > docker build .
# > docker run <CONTAINER_ID>
FROM node:18.20.8-bookworm@sha256:c6ae79e38498325db67193d391e6ec1d224d96c693a8a4d943498556716d3783

FROM node:10
RUN apt-get update && apt-get install -y --no-install-recommends chromium=140.0.7339.185-1~deb12u1 \
&& rm -rf /var/lib/apt/lists/*

COPY .. /home/node/
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium

WORKDIR /home/node

COPY .. .

RUN npm --quiet set progress=false \
&& npm install --only=prod --no-optional \
&& echo "Installed NPM packages:" \
&& npm list || true \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version
&& npm install --no-optional \
&& echo "Installed NPM packages:" \
&& npm list || true \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version

CMD cd /home/node && npm test
CMD ["npm", "test"]
50 changes: 41 additions & 9 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
# Tests

To run the tests, you need to add the following line to your `/etc/hosts`:
## Docker (recommended)

Since Linux and macOS handle sockets differently, please run tests in a Docker container
to have a consistent Linux environment for running tests.

```bash
npm run test:docker
```
# Used by proxy-chain NPM package tests
127.0.0.1 localhost
127.0.0.1 localhost-test
```

The `localhost` entry is for avoiding dual-stack issues, e.g. when the test server listens at ::1
(results of getaddrinfo have specifed order) and the client attempts to connect to 127.0.0.1 .
Note: for test in Docker no changes in `/etc/hosts` needed.

## Local Machine

### Prerequisites

1. Node.js 18+ (see `.nvmrc` for exact version)
2. For MacOS with ARM CPUs install Rosetta (workaround for puppeteer)
3. Update `/etc/hosts`

```bash
# Used by proxy-chain NPM package tests
127.0.0.1 localhost
127.0.0.1 localhost-test
```

The `localhost` entry is for avoiding dual-stack issues, e.g. when the test server listens at ::1
(results of getaddrinfo have specified order) and the client attempts to connect to 127.0.0.1 .

The `localhost-test` entry is a workaround to PhantomJS' behavior where it skips proxy servers for
localhost addresses.

### Run tests

1. Run all tests

```bash
npm run test
```

2. Run specific tests

The `localhost-test` entry is a workaround to PhantomJS' behavior where it skips proxy servers for
localhost addresses.
```bash
npm run test test/anonymize_proxy.js
```
2 changes: 2 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ const puppeteerGet = (url, proxyUrl) => {
HTTP_PROXY: parsed.origin,
} : {},
ignoreHTTPSErrors: true,
headless: "new",
args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage']
});

try {
Expand Down
Loading