Task: Add client headers and auth for tunnel connection and updated the configs load for init params for http tunnel client
This commit is contained in:
parent
e925d37e1b
commit
e5db37bf5d
16
README.md
16
README.md
@ -1,12 +1,28 @@
|
|||||||
# CUBETIQ HTTP Tunnel Client
|
# CUBETIQ HTTP Tunnel Client
|
||||||
|
|
||||||
A lightweight http tunnel client using nodejs and socket.io client.
|
A lightweight http tunnel client using nodejs and socket.io client.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
- Generate Client Key
|
- Generate Client Key
|
||||||
|
|
||||||
```
|
```
|
||||||
npx @cubetiq/http-tunnel config client new
|
npx @cubetiq/http-tunnel config client new
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- Set Client Token (Required, contact to vendor)
|
||||||
|
|
||||||
|
```
|
||||||
|
npx @cubetiq/http-tunnel config token $TOKEN
|
||||||
|
```
|
||||||
|
|
||||||
|
- Start Client
|
||||||
|
|
||||||
|
```
|
||||||
|
npx @cubetiq/http-tunnel start
|
||||||
|
```
|
||||||
|
|
||||||
### Contributors
|
### Contributors
|
||||||
|
|
||||||
- Original [web-tunnel](https://github.com/web-tunnel/lite-http-tunnel-client)
|
- Original [web-tunnel](https://github.com/web-tunnel/lite-http-tunnel-client)
|
||||||
- Sambo Chea <sombochea@cubetiqs.com>
|
- Sambo Chea <sombochea@cubetiqs.com>
|
41
client.js
41
client.js
@ -10,6 +10,7 @@ const { generateUUID, addPrefixOnHttpSchema } = require("./util");
|
|||||||
|
|
||||||
// constants
|
// constants
|
||||||
const PROFILE_DEFAULT = "default";
|
const PROFILE_DEFAULT = "default";
|
||||||
|
const SERVER_DEFAULT_URL = "https://lt.ctdn.net";
|
||||||
|
|
||||||
// create socket instance
|
// create socket instance
|
||||||
let socket = null;
|
let socket = null;
|
||||||
@ -28,20 +29,28 @@ function initClient(options) {
|
|||||||
// Current style using sub-domain: https://{{clientId}}-tunnel.myhostingdomain.com
|
// Current style using sub-domain: https://{{clientId}}-tunnel.myhostingdomain.com
|
||||||
// (Original server: https://tunnel.myhostingdomain.com)
|
// (Original server: https://tunnel.myhostingdomain.com)
|
||||||
const profile = options.profile || PROFILE_DEFAULT;
|
const profile = options.profile || PROFILE_DEFAULT;
|
||||||
const clientId = `${options.clientId || generateUUID()}`;
|
const clientId = `${options.clientId || options.apiKey || generateUUID()}`;
|
||||||
const clientIdSub = `${clientId}-${profile}-`;
|
const clientIdSub =
|
||||||
|
profile === PROFILE_DEFAULT ? `${clientId}-` : `${clientId}-${profile}-`;
|
||||||
const serverUrl = addPrefixOnHttpSchema(options.server, clientIdSub);
|
const serverUrl = addPrefixOnHttpSchema(options.server, clientIdSub);
|
||||||
|
|
||||||
|
const defaultParams = {
|
||||||
|
apiKey: options.apiKey,
|
||||||
|
clientId: options.clientId,
|
||||||
|
profile: options.profile,
|
||||||
|
clientIdSub: clientIdSub,
|
||||||
|
serverUrl: serverUrl,
|
||||||
|
};
|
||||||
|
|
||||||
const initParams = {
|
const initParams = {
|
||||||
path: "/$cubetiq_http_tunnel",
|
path: "/$cubetiq_http_tunnel",
|
||||||
transports: ["websocket"],
|
transports: ["websocket"],
|
||||||
auth: {
|
auth: {
|
||||||
token: options.token,
|
token: options.token,
|
||||||
apiKey: options.apiKey,
|
...defaultParams,
|
||||||
clientId: options.clientId,
|
},
|
||||||
profile: options.profile,
|
headers: {
|
||||||
clientIdSub: clientIdSub,
|
...defaultParams,
|
||||||
serverUrl: serverUrl,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -183,17 +192,23 @@ program
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!config.server) {
|
if (!config.server) {
|
||||||
console.error("Please set remote tunnel server firstly!");
|
config.server = SERVER_DEFAULT_URL;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.token) {
|
if (!config.token) {
|
||||||
console.error(`Please set jwt token for ${config.server} firstly!`);
|
console.info(`Please set token for ${config.server}!`);
|
||||||
|
console.info(
|
||||||
|
"If you don't have token yet, please contact to: sombochea@cubetiqs.com"
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.clientId) {
|
if (!config.clientId) {
|
||||||
console.error(`Please create client for ${config.server} firstly!`);
|
if (!config.apiKey) {
|
||||||
|
console.info(`Please create client for ${config.server}!`);
|
||||||
|
} else {
|
||||||
|
config.clientId = config.apiKey;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,6 +271,10 @@ program
|
|||||||
config[key] = value;
|
config[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!config.clientId && config.apiKey) {
|
||||||
|
config.clientId = config.apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2));
|
fs.writeFileSync(configFilePath, JSON.stringify(config, null, 2));
|
||||||
console.log(`${type} config saved successfully to: ${configFilePath}!`);
|
console.log(`${type} config saved successfully to: ${configFilePath}!`);
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cubetiq/http-tunnel-client",
|
"name": "@cubetiq/http-tunnel-client",
|
||||||
"version": "1.0.0",
|
"version": "0.0.1",
|
||||||
"description": "A lightweight http tunnel client using nodejs and socket.io client.",
|
"description": "A lightweight http tunnel client using nodejs and socket.io client.",
|
||||||
"main": "client.js",
|
"main": "client.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user