mirror of
https://github.com/openziti/zrok.git
synced 2025-05-30 14:49:35 +02:00
transition 'pastefrom' example to use 'ziti.listen', 'ziti.write', 'ziti.dial'
This commit is contained in:
parent
0b2379d6d1
commit
c8d48af5c4
@ -14,19 +14,35 @@ program
|
|||||||
var data = readlineSync.question('Input some text... ');
|
var data = readlineSync.question('Input some text... ');
|
||||||
|
|
||||||
console.log("data is: ", data)
|
console.log("data is: ", data)
|
||||||
|
|
||||||
|
var enc = new TextEncoder();
|
||||||
|
var buf = enc.encode(data); //
|
||||||
|
|
||||||
let root = zrok.Load()
|
let root = zrok.Load()
|
||||||
await zrok.init( root ).catch(( err: Error ) => { console.error(err); return process.exit(1) });
|
await zrok.init( root ).catch(( err: Error ) => { console.error(err); return process.exit(1) });
|
||||||
zrok.setLogLevel(0)
|
zrok.setLogLevel(0)
|
||||||
console.log("setting up zrok.CreateShare...")
|
console.log("setting up zrok.CreateShare...")
|
||||||
let shr = await zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PRIVATE_SHARE_MODE, "pastebin", ["private"]));
|
let shr = await zrok.CreateShare(root, new zrok.ShareRequest(zrok.TCP_TUNNEL_BACKEND_MODE, zrok.PRIVATE_SHARE_MODE, "pastebin", ["private"]));
|
||||||
console.log("access your pastebin using 'pastefrom ", shr.Token)
|
console.log(`access your pastebin using 'pastefrom ${shr.Token}'`)
|
||||||
let app = zrok.express( shr.Token );
|
|
||||||
app.get('/',function(_: Request,res: any){
|
zrok.listener(
|
||||||
res.write(data)
|
shr.Token,
|
||||||
res.end()
|
(data: any) => { // listenCallback
|
||||||
});
|
},
|
||||||
app.listen(undefined, () => {
|
(data: any) => { // listenClientCallback
|
||||||
})
|
},
|
||||||
|
(data: any) => { // clientConnectCallback
|
||||||
|
// when we receive a client connection, then write the data to them
|
||||||
|
zrok.write(
|
||||||
|
data.client,
|
||||||
|
buf,
|
||||||
|
(data: any) => { // writeCallback
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
(data: any) => { // clientDataCallback
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
// Delete the private share upon CTRL-C
|
// Delete the private share upon CTRL-C
|
||||||
process.on('SIGINT', async () => {
|
process.on('SIGINT', async () => {
|
||||||
@ -47,35 +63,26 @@ program
|
|||||||
await zrok.init(root).catch((err: any) => {
|
await zrok.init(root).catch((err: any) => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
});
|
});
|
||||||
|
zrok.setLogLevel(0)
|
||||||
let acc = await zrok.CreateAccess(root, new zrok.AccessRequest(shrToken))
|
let acc = await zrok.CreateAccess(root, new zrok.AccessRequest(shrToken))
|
||||||
|
|
||||||
ziti.httpRequest(
|
var dec = new TextDecoder("utf-8");
|
||||||
|
|
||||||
|
zrok.dialer(
|
||||||
|
root,
|
||||||
shrToken,
|
shrToken,
|
||||||
undefined,
|
(data: any) => { // on_connect_cb
|
||||||
'GET',
|
|
||||||
'/',
|
|
||||||
[],
|
|
||||||
(data: any) => { // on_req_cb
|
|
||||||
console.log("in on_req_cb")
|
|
||||||
console.log("data is: ", data)
|
|
||||||
},
|
},
|
||||||
(data: any) => { // on_resp_cb
|
(data: any) => { // on_data_cb
|
||||||
console.log("in on_resp_cb")
|
console.log("data is: ", dec.decode(data));
|
||||||
console.log("data is: ", data)
|
process.exit(0);
|
||||||
},
|
},
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
process.on('SIGINT', async () => {
|
||||||
|
process.exit(15);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
program.parse(process.argv)
|
program.parse(process.argv)
|
||||||
|
@ -61,16 +61,10 @@ export class Root {
|
|||||||
|
|
||||||
public async Client(): Promise<Configuration> {
|
public async Client(): Promise<Configuration> {
|
||||||
let apiEndpoint = this.ApiEndpoint()
|
let apiEndpoint = this.ApiEndpoint()
|
||||||
|
let conf = new Configuration({
|
||||||
//let headers = {
|
basePath: apiEndpoint.endpoint + '/api/v1',
|
||||||
// "X-TOKEN": this.env.Token
|
apiKey: this.env.Token,
|
||||||
//}
|
})
|
||||||
|
|
||||||
let conf = new Configuration({
|
|
||||||
basePath: apiEndpoint.endpoint + '/api/v1',
|
|
||||||
apiKey: this.env.Token,
|
|
||||||
//headers: headers
|
|
||||||
})
|
|
||||||
|
|
||||||
let mapi = new MetadataApi(conf)
|
let mapi = new MetadataApi(conf)
|
||||||
let ver: Promise<string> = mapi.version()
|
let ver: Promise<string> = mapi.version()
|
||||||
|
@ -14,6 +14,15 @@ export function dialer(root: Root, shrToken: string, connectCallback: any, dataC
|
|||||||
ziti.dial(shrToken, false, connectCallback, dataCallback)
|
ziti.dial(shrToken, false, connectCallback, dataCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function listener(shrToken: string, listenCallback: any, listenClientCallback: any, clientConnectCallback: any, clientDataCallback: any): ziti.listener {
|
||||||
|
ziti.listen(shrToken, 0, listenCallback, listenClientCallback, clientConnectCallback, clientDataCallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function write(conn: any, buf: any, writeCallback: any ){
|
||||||
|
ziti.write(conn, buf, writeCallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function setLogLevel(level:number) {
|
export function setLogLevel(level:number) {
|
||||||
ziti.setLogLevel(level)
|
ziti.setLogLevel(level)
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user