checkpoint

This commit is contained in:
Curt Tudor
2024-03-25 09:45:04 -06:00
parent 3a9f26eeaf
commit 68ac00b344
120 changed files with 0 additions and 97 deletions

File diff suppressed because it is too large Load Diff

View 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"
}
}

View 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();

View File

@ -0,0 +1,12 @@
{
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"strict": true,
"target": "es6",
"module": "commonjs",
"sourceMap": true,
"esModuleInterop": true,
"moduleResolution": "node"
}
}