Skip to content

Commit

Permalink
WHATWG URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mrluanma committed Mar 13, 2024
1 parent deea801 commit e63904b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ npm install
Then run:

```
$ node local.js -s still-tor-8707.herokuapp.com -l 1080 -m aes-128-cfb -k foobar -r 80
$ node local.js -s ws://still-tor-8707.herokuapp.com -l 1080 -m aes-128-cfb -k foobar -r 80
server listening at { address: '127.0.0.1', family: 'IPv4', port: 1080 }
```

Expand Down
3 changes: 1 addition & 2 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"server": "127.0.0.1",
"server": "ws://127.0.0.1",
"local_address": "127.0.0.1",
"scheme": "ws",
"local_port": 1080,
"remote_port": 8080,
"password": "`try*(^^$some^$%^complex>:<>?~password/",
Expand Down
24 changes: 5 additions & 19 deletions local.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import net from 'net';
import url from 'url';
import http from 'http';
import fs from 'fs';
import WebSocket from 'ws';
import parseArgs from 'minimist';
Expand All @@ -18,14 +16,7 @@ const options = {
c: 'config_file',
m: 'method',
},
string: [
'local_address',
'server',
'password',
'config_file',
'method',
'scheme',
],
string: ['local_address', 'server', 'password', 'config_file', 'method'],
default: {
config_file: './config.json',
},
Expand All @@ -39,7 +30,6 @@ for (let k in configFromArgs) {
config[k] = v;
}

const SCHEME = config.scheme;
let SERVER = config.server;
const REMOTE_PORT = config.remote_port;
const LOCAL_ADDRESS = config.local_address;
Expand All @@ -54,19 +44,15 @@ if (HTTPPROXY) {
}

const prepareServer = function (address) {
const serverUrl = url.parse(address);
serverUrl.slashes = true;
if (!serverUrl.protocol) {
serverUrl.protocol = SCHEME;
}
const serverUrl = new URL(address);
if (!serverUrl.hostname) {
serverUrl.hostname = address;
serverUrl.pathname = '/';
}
if (!serverUrl.port) {
serverUrl.port = REMOTE_PORT;
}
return url.format(serverUrl);
return serverUrl.toString();
};

if (SERVER instanceof Array) {
Expand Down Expand Up @@ -181,11 +167,11 @@ var server = net.createServer(function (connection) {
if (HTTPPROXY) {
// WebSocket endpoint for the proxy to connect to
const endpoint = aServer;
const parsed = url.parse(endpoint);
const parsed = new URL(endpoint);
//console.log('attempting to connect to WebSocket %j', endpoint);

// create an instance of the `HttpsProxyAgent` class with the proxy server information
const opts = url.parse(HTTPPROXY);
const opts = new URL(HTTPPROXY);

// IMPORTANT! Set the `secureEndpoint` option to `false` when connecting
// over "ws://", but `true` when connecting over "wss://"
Expand Down

0 comments on commit e63904b

Please sign in to comment.