mirror of
https://github.com/openziti/zrok.git
synced 2024-11-25 01:23:49 +01:00
checkpoint
This commit is contained in:
parent
6c905538db
commit
3a9f26eeaf
2217
sdk/node/examples/http-server/package-lock.json
generated
Normal file
2217
sdk/node/examples/http-server/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
sdk/node/examples/http-server/package.json
Normal file
19
sdk/node/examples/http-server/package.json
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"@openziti/ziti-sdk-nodejs": "^0.14.2",
|
||||||
|
"commander": "^11.1.0",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"path": "^0.12.7",
|
||||||
|
"readline-sync": "^1.4.10",
|
||||||
|
"zrok": "../../sdk/dist"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20.9.0",
|
||||||
|
"nodemon": "^3.0.1",
|
||||||
|
"ts-node": "^10.9.1",
|
||||||
|
"typescript": "^5.4.3"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "npx tsc"
|
||||||
|
}
|
||||||
|
}
|
55
sdk/node/examples/http-server/src/index.ts
Normal file
55
sdk/node/examples/http-server/src/index.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
const { Command } = require("commander");
|
||||||
|
const zrok = require("zrok")
|
||||||
|
|
||||||
|
|
||||||
|
const program = new Command();
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('http-server')
|
||||||
|
.version("1.0.0")
|
||||||
|
.description("command to host an HTTP Server")
|
||||||
|
.action(async () => {
|
||||||
|
|
||||||
|
// Load the zrok env
|
||||||
|
let root = zrok.Load()
|
||||||
|
|
||||||
|
// Authenticate with the Ziti network
|
||||||
|
await zrok.init( root ).catch(( err: Error ) => { console.error(err); return process.exit(1) });
|
||||||
|
|
||||||
|
// Set this to a larger value (e.g. 10) to trace lower-level Ziti SDK activity
|
||||||
|
zrok.setLogLevel(0)
|
||||||
|
|
||||||
|
// Create the zrok private share that will represent this web server
|
||||||
|
console.log("Now creating your private zrok share...")
|
||||||
|
let shr = await zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PRIVATE_SHARE_MODE, "http-server", ["private"]));
|
||||||
|
console.log(`access your private HTTP Server on another machine using: 'zrok access private ${shr.Token}'`)
|
||||||
|
|
||||||
|
// Create a NodeJS Express web server that listens NOT on a TCP port, but for incoming Ziti connections to the private zrok share
|
||||||
|
let app = zrok.express( shr.Token );
|
||||||
|
|
||||||
|
// Set up a simple route
|
||||||
|
let reqCtr = 0;
|
||||||
|
app.get('/', function(_: Request, res: any){
|
||||||
|
reqCtr++;
|
||||||
|
console.log(`received a GET request... reqCtr[${reqCtr}]`);
|
||||||
|
res.write(`Hello zrok! reqCtr[${reqCtr}]`)
|
||||||
|
res.end()
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start listening for incoming requests
|
||||||
|
app.listen(undefined, () => {
|
||||||
|
console.log(`private HTTP Server is now listening for incoming requests`)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Delete the private share upon CTRL-C
|
||||||
|
process.on('SIGINT', async () => {
|
||||||
|
console.log("Now deleting your private zrok share...")
|
||||||
|
await zrok.DeleteShare(root, shr)
|
||||||
|
process.exit(15);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
program.parse(process.argv)
|
||||||
|
const options = program.opts();
|
12
sdk/node/examples/http-server/tsconfig.json
Normal file
12
sdk/node/examples/http-server/tsconfig.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": "src",
|
||||||
|
"outDir": "dist",
|
||||||
|
"strict": true,
|
||||||
|
"target": "es6",
|
||||||
|
"module": "commonjs",
|
||||||
|
"sourceMap": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"moduleResolution": "node"
|
||||||
|
}
|
||||||
|
}
|
67
sdk/node/examples/pastebin/dist/index.js
vendored
67
sdk/node/examples/pastebin/dist/index.js
vendored
@ -8,53 +8,88 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const { Command } = require("commander");
|
const { Command } = require("commander");
|
||||||
const zrok = require("zrok");
|
const zrok = require("zrok");
|
||||||
const ziti = require('@openziti/ziti-sdk-nodejs');
|
const ziti = require('@openziti/ziti-sdk-nodejs');
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
|
var readlineSync = require('readline-sync');
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
program
|
program
|
||||||
.command('copyto')
|
.command('copyto')
|
||||||
.version("1.0.0")
|
.version("1.0.0")
|
||||||
.description("command to host content to be pastedfrom'd")
|
.description("command to host content to be pastedfrom'd")
|
||||||
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
var data = readlineSync.question('Input some text... ');
|
||||||
|
console.log("data is: ", data);
|
||||||
let root = zrok.Load();
|
let root = zrok.Load();
|
||||||
yield zrok.init(root);
|
yield zrok.init(root);
|
||||||
//await ziti.init( root.env.ZitiIdentity ).catch(( err: Error ) => { console.error(err); return process.exit(1) });
|
//await ziti.init( root.env.ZitiIdentity ).catch(( err: Error ) => { console.error(err); return process.exit(1) });
|
||||||
ziti.setLogLevel(10);
|
ziti.setLogLevel(0);
|
||||||
|
console.log("setting up zrok.CreateShare...");
|
||||||
let shr = yield zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PUBLIC_SHARE_MODE, "pastebin", ["public"]));
|
let shr = yield zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PUBLIC_SHARE_MODE, "pastebin", ["public"]));
|
||||||
console.log("setting up app");
|
// console.log("zrok share is: ",shr)
|
||||||
let service = "ns5ix2brb61f";
|
// console.log("setting up app")
|
||||||
console.log("attempting to bind to service: " + shr.Token);
|
// let service = "ns5ix2brb61f"
|
||||||
|
// console.log("attempting to bind to service: "+ shr.Token)
|
||||||
|
console.log("access your pastebin using 'pastefrom ", shr.Token);
|
||||||
|
// let listener = await zrok.NewListener(shr.Token, root)
|
||||||
|
// console.log("zrok listener is: ", listener)
|
||||||
let app = ziti.express(express, shr.Token);
|
let app = ziti.express(express, shr.Token);
|
||||||
console.log("after setting up app");
|
// console.log("after setting up app")
|
||||||
app.get('/', function (_, res) {
|
app.get('/', function (_, res) {
|
||||||
res.write("Test");
|
// console.log("received a GET request")
|
||||||
|
res.write(data);
|
||||||
|
res.end();
|
||||||
});
|
});
|
||||||
console.log("after setting up get");
|
// console.log("after setting up get")
|
||||||
app.listen(undefined, () => {
|
app.listen(undefined, () => {
|
||||||
console.log(`Example app listening!`);
|
// console.log(`Example app listening!`)
|
||||||
});
|
});
|
||||||
console.log("after listen");
|
// console.log("after listen")
|
||||||
zrok.DeleteShare(root, shr);
|
// zrok.DeleteShare(root, shr);
|
||||||
}));
|
}));
|
||||||
program
|
program
|
||||||
.command('pastefrom <shrToken>')
|
.command('pastefrom <shrToken>')
|
||||||
.version("1.0.0")
|
.version("1.0.0")
|
||||||
.description("command to paste content from coptyo")
|
.description("command to paste content from coptyo")
|
||||||
.action((shrToken) => __awaiter(void 0, void 0, void 0, function* () {
|
.action((shrToken) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
//ziti.setLogLevel(10)
|
// ziti.setLogLevel(99)
|
||||||
console.log('pastefrom command called', shrToken);
|
|
||||||
let root = zrok.Load();
|
let root = zrok.Load();
|
||||||
yield zrok.init(root).catch((err) => {
|
yield zrok.init(root).catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
let acc = yield zrok.CreateAccess(root, new zrok.AccessRequest(shrToken));
|
let acc = yield zrok.CreateAccess(root, new zrok.AccessRequest(shrToken));
|
||||||
console.log("about to dial");
|
// console.log("zrok.CreateAccess returned: ", acc)
|
||||||
zrok.dialer(root, shrToken, (data) => {
|
// console.log("about to ziti.httpRequest: ", shrToken)
|
||||||
console.log("in callback");
|
// setTimeout(function() {
|
||||||
console.log(data.toString());
|
ziti.httpRequest(shrToken, undefined, 'GET', '/', [], (data) => {
|
||||||
|
console.log("in on_req_cb");
|
||||||
|
console.log("data is: ", data);
|
||||||
|
}, (data) => {
|
||||||
|
console.log("in on_resp_cb");
|
||||||
|
console.log("data is: ", data);
|
||||||
|
}, (data) => {
|
||||||
|
console.log("in on_resp_data_cb");
|
||||||
|
console.log("data is: ", data);
|
||||||
|
if (data.body) {
|
||||||
|
console.log('----------- pastefrom is: ', data.body.toString());
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
// }, 5000);
|
||||||
|
// zrok.dialer(
|
||||||
|
// root,
|
||||||
|
// shrToken,
|
||||||
|
// (conn: any) => {
|
||||||
|
// console.log("in connectCallback")
|
||||||
|
// console.log("conn is: ", conn)
|
||||||
|
// },
|
||||||
|
// (dataData: any) => {
|
||||||
|
// console.log("in dataCallback")
|
||||||
|
// console.log(dataData.toString())
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}));
|
}));
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
const options = program.opts();
|
const options = program.opts();
|
||||||
|
2
sdk/node/examples/pastebin/dist/index.js.map
vendored
2
sdk/node/examples/pastebin/dist/index.js.map
vendored
@ -1 +1 @@
|
|||||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACzC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;AAC5B,MAAM,IAAI,GAAI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ACZ,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAA;QAC5B,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;IAChC,CAAC,EACD,CAAC,IAAS,EAAE,EAAE;QACZ,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAA;QACjC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QAC9B,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,4BAA4B,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IAEH,CAAC,CACF,CAAC;IAEJ,YAAY;IAIZ,eAAe;IACf,WAAW;IACX,eAAe;IACf,qBAAqB;IACrB,wCAAwC;IACxC,qCAAqC;IAGrC,OAAO;IACP,yBAAyB;IACzB,qCAAqC;IACrC,uCAAuC;IACvC,MAAM;IACN,KAAK;AACP,CAAC,CAAA,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;AAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC"}
|
28
sdk/node/examples/pastebin/package-lock.json
generated
28
sdk/node/examples/pastebin/package-lock.json
generated
@ -9,13 +9,14 @@
|
|||||||
"commander": "^11.1.0",
|
"commander": "^11.1.0",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
|
"readline-sync": "^1.4.10",
|
||||||
"zrok": "../../sdk/dist"
|
"zrok": "../../sdk/dist"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.9.0",
|
"@types/node": "^20.9.0",
|
||||||
"nodemon": "^3.0.1",
|
"nodemon": "^3.0.1",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.4.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"../../sdk/dist": {},
|
"../../sdk/dist": {},
|
||||||
@ -1649,6 +1650,14 @@
|
|||||||
"node": ">=8.10.0"
|
"node": ">=8.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/readline-sync": {
|
||||||
|
"version": "1.4.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz",
|
||||||
|
"integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/require-directory": {
|
"node_modules/require-directory": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||||
@ -2008,9 +2017,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "5.3.3",
|
"version": "5.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz",
|
||||||
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
|
"integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
@ -3430,6 +3439,11 @@
|
|||||||
"picomatch": "^2.2.1"
|
"picomatch": "^2.2.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"readline-sync": {
|
||||||
|
"version": "1.4.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz",
|
||||||
|
"integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw=="
|
||||||
|
},
|
||||||
"require-directory": {
|
"require-directory": {
|
||||||
"version": "2.1.1",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
|
||||||
@ -3690,9 +3704,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"version": "5.3.3",
|
"version": "5.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.3.tgz",
|
||||||
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
|
"integrity": "sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"undefsafe": {
|
"undefsafe": {
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
"commander": "^11.1.0",
|
"commander": "^11.1.0",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"path": "^0.12.7",
|
"path": "^0.12.7",
|
||||||
|
"readline-sync": "^1.4.10",
|
||||||
"zrok": "../../sdk/dist"
|
"zrok": "../../sdk/dist"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.9.0",
|
"@types/node": "^20.9.0",
|
||||||
"nodemon": "^3.0.1",
|
"nodemon": "^3.0.1",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.4.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "npx tsc"
|
"build": "npx tsc"
|
||||||
|
@ -2,6 +2,8 @@ const { Command } = require("commander");
|
|||||||
const zrok = require("zrok")
|
const zrok = require("zrok")
|
||||||
const ziti = require('@openziti/ziti-sdk-nodejs')
|
const ziti = require('@openziti/ziti-sdk-nodejs')
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
var readlineSync = require('readline-sync');
|
||||||
|
import fs from "node:fs"
|
||||||
|
|
||||||
|
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
@ -11,25 +13,38 @@ program
|
|||||||
.version("1.0.0")
|
.version("1.0.0")
|
||||||
.description("command to host content to be pastedfrom'd")
|
.description("command to host content to be pastedfrom'd")
|
||||||
.action(async () => {
|
.action(async () => {
|
||||||
|
var data = readlineSync.question('Input some text... ');
|
||||||
|
|
||||||
|
console.log("data is: ", data)
|
||||||
let root = zrok.Load()
|
let root = zrok.Load()
|
||||||
await zrok.init(root);
|
await zrok.init(root);
|
||||||
//await ziti.init( root.env.ZitiIdentity ).catch(( err: Error ) => { console.error(err); return process.exit(1) });
|
//await ziti.init( root.env.ZitiIdentity ).catch(( err: Error ) => { console.error(err); return process.exit(1) });
|
||||||
ziti.setLogLevel(10)
|
ziti.setLogLevel(0)
|
||||||
|
console.log("setting up zrok.CreateShare...")
|
||||||
let shr = await zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PUBLIC_SHARE_MODE, "pastebin", ["public"]));
|
let shr = await zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PUBLIC_SHARE_MODE, "pastebin", ["public"]));
|
||||||
console.log("setting up app")
|
// console.log("zrok share is: ",shr)
|
||||||
let service = "ns5ix2brb61f"
|
// console.log("setting up app")
|
||||||
console.log("attempting to bind to service: "+ shr.Token)
|
// let service = "ns5ix2brb61f"
|
||||||
|
// console.log("attempting to bind to service: "+ shr.Token)
|
||||||
|
console.log("access your pastebin using 'pastefrom ", shr.Token)
|
||||||
|
|
||||||
|
// let listener = await zrok.NewListener(shr.Token, root)
|
||||||
|
// console.log("zrok listener is: ", listener)
|
||||||
|
|
||||||
|
|
||||||
let app = ziti.express( express, shr.Token );
|
let app = ziti.express( express, shr.Token );
|
||||||
console.log("after setting up app")
|
// console.log("after setting up app")
|
||||||
app.get('/',function(_: Request,res: any){
|
app.get('/',function(_: Request,res: any){
|
||||||
res.write("Test")
|
// console.log("received a GET request")
|
||||||
|
res.write(data)
|
||||||
|
res.end()
|
||||||
});
|
});
|
||||||
console.log("after setting up get")
|
// console.log("after setting up get")
|
||||||
app.listen(undefined, () => {
|
app.listen(undefined, () => {
|
||||||
console.log(`Example app listening!`)
|
// console.log(`Example app listening!`)
|
||||||
})
|
})
|
||||||
console.log("after listen")
|
// console.log("after listen")
|
||||||
zrok.DeleteShare(root, shr);
|
// zrok.DeleteShare(root, shr);
|
||||||
});
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
@ -38,18 +53,64 @@ program
|
|||||||
.description("command to paste content from coptyo")
|
.description("command to paste content from coptyo")
|
||||||
.action(async (shrToken: string) => {
|
.action(async (shrToken: string) => {
|
||||||
|
|
||||||
//ziti.setLogLevel(10)
|
// ziti.setLogLevel(99)
|
||||||
console.log('pastefrom command called', shrToken);
|
|
||||||
let root = zrok.Load();
|
let root = zrok.Load();
|
||||||
await zrok.init(root).catch((err: any) => {
|
await zrok.init(root).catch((err: any) => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
});
|
});
|
||||||
let acc = await zrok.CreateAccess(root, new zrok.AccessRequest(shrToken))
|
let acc = await zrok.CreateAccess(root, new zrok.AccessRequest(shrToken))
|
||||||
console.log("about to dial")
|
// console.log("zrok.CreateAccess returned: ", acc)
|
||||||
zrok.dialer(root, shrToken, (data: any) => {
|
|
||||||
console.log("in callback")
|
// console.log("about to ziti.httpRequest: ", shrToken)
|
||||||
console.log(data.toString())
|
|
||||||
});
|
// setTimeout(function() {
|
||||||
|
|
||||||
|
ziti.httpRequest(
|
||||||
|
shrToken,
|
||||||
|
undefined,
|
||||||
|
'GET',
|
||||||
|
'/',
|
||||||
|
[],
|
||||||
|
(data: any) => { // on_req_cb
|
||||||
|
console.log("in on_req_cb")
|
||||||
|
console.log("data is: ", data)
|
||||||
|
},
|
||||||
|
(data: any) => { // on_resp_cb
|
||||||
|
console.log("in on_resp_cb")
|
||||||
|
console.log("data is: ", data)
|
||||||
|
},
|
||||||
|
async (data: any) => { // on_resp_data_cb
|
||||||
|
console.log("in on_resp_data_cb")
|
||||||
|
console.log("data is: ", data)
|
||||||
|
if (data.body) {
|
||||||
|
console.log('----------- pastefrom is: ', data.body.toString());
|
||||||
|
|
||||||
|
await zrok.DeleteAccess(root, acc)
|
||||||
|
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// }, 5000);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// zrok.dialer(
|
||||||
|
// root,
|
||||||
|
// shrToken,
|
||||||
|
// (conn: any) => {
|
||||||
|
// console.log("in connectCallback")
|
||||||
|
// console.log("conn is: ", conn)
|
||||||
|
|
||||||
|
|
||||||
|
// },
|
||||||
|
// (dataData: any) => {
|
||||||
|
// console.log("in dataCallback")
|
||||||
|
// console.log(dataData.toString())
|
||||||
|
// }
|
||||||
|
// );
|
||||||
});
|
});
|
||||||
|
|
||||||
program.parse(process.argv)
|
program.parse(process.argv)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "zrok",
|
"name": "zrok",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "SDK to enable programmatic usee of the zrok sharing methods",
|
"description": "SDK to enable programmatic use of the zrok sharing methods",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
@ -30,7 +30,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/openziti/zrok#readme",
|
"homepage": "https://github.com/openziti/zrok#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@openziti/ziti-sdk-nodejs": "^0.14.2",
|
"@openziti/ziti-sdk-nodejs": "^0.15.0",
|
||||||
"axios": "^1.6.2",
|
"axios": "^1.6.2",
|
||||||
"express": "^4.18.2"
|
"express": "^4.18.2"
|
||||||
},
|
},
|
||||||
|
@ -153,9 +153,13 @@ function loadMetadata(): Metadata {
|
|||||||
|
|
||||||
function loadConfig(): Config {
|
function loadConfig(): Config {
|
||||||
let cf = configFile()
|
let cf = configFile()
|
||||||
|
if (fs.existsSync(cf)) { // the config.json file may not be present
|
||||||
let data = fs.readFileSync(cf)
|
let data = fs.readFileSync(cf)
|
||||||
let serial = JSON.parse(data.toString())
|
let serial = JSON.parse(data.toString())
|
||||||
return new Config(serial.api_endpoint)
|
return new Config(serial.api_endpoint)
|
||||||
|
} else {
|
||||||
|
return new Config('')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadEnvironment(): Environment {
|
function loadEnvironment(): Environment {
|
||||||
|
@ -26,10 +26,10 @@ export async function CreateAccess(root: Root, request: model.AccessRequest): Pr
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (shr.frontendToken == undefined) {
|
if (shr.frontendToken == undefined) {
|
||||||
throw new Error("excpedted frontend token from access. Got none")
|
throw new Error("expected frontend token from access. Got none")
|
||||||
}
|
}
|
||||||
if (shr.backendMode == undefined) {
|
if (shr.backendMode == undefined) {
|
||||||
throw new Error("excpedted backend mode from access. Got none")
|
throw new Error("expected backend mode from access. Got none")
|
||||||
}
|
}
|
||||||
|
|
||||||
return new model.Access(shr.frontendToken, request.ShareToken, shr.backendMode)
|
return new model.Access(shr.frontendToken, request.ShareToken, shr.backendMode)
|
||||||
|
@ -10,6 +10,10 @@ export async function init(root: Root): Promise<any> {
|
|||||||
return ziti.init(root.ZitiIdentityNamed(root.EnvironmentIdentityName()))
|
return ziti.init(root.ZitiIdentityNamed(root.EnvironmentIdentityName()))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function dialer(root: Root, shrToken: string, callback: any): ziti.dialer {
|
export function dialer(root: Root, shrToken: string, connectCallback: any, dataCallback: any): ziti.dialer {
|
||||||
ziti.listen(shrToken, false, undefined, callback)
|
ziti.dial(shrToken, false, connectCallback, dataCallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setLogLevel(level:number) {
|
||||||
|
ziti.setLogLevel(level)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user