Skip to content

Commit

Permalink
✨ CLI: Expose EASY API with --tunnel #2314
Browse files Browse the repository at this point in the history
  • Loading branch information
smashah committed Nov 24, 2021
1 parent f0bf4bc commit bc60394
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 35 deletions.
105 changes: 71 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "4.23.18",
"licenseCheckUrl": "https://openwa.dev/license-check",
"brokenMethodReportUrl": "https://openwa.dev/report-bm",
"patches": "https://cdn.openwa.dev/patches.json",
"patches": "http://127.0.0.1:5503/functions/patches.json",
"stickerUrl": "https://sticker-api.openwa.dev",
"description": " 💬 🤖 The most reliable NodeJS whatsapp library for chatbots with advanced features.",
"main": "dist/index.js",
Expand Down Expand Up @@ -69,6 +69,7 @@
"@types/express": "^4.17.11",
"@types/fs-extra": "^9.0.11",
"@types/line-reader": "0.0.34",
"@types/localtunnel": "^2.0.1",
"@types/marked": "^3.0.0",
"@types/mime-types": "^2.1.0",
"@types/node": "^16.0.0",
Expand Down Expand Up @@ -124,6 +125,7 @@
"image-type": "^4.1.0",
"is-url-superb": "^5.0.0",
"json5": "^2.2.0",
"localtunnel": "^2.0.2",
"lodash.uniq": "^4.5.0",
"meow": "^9.0.0",
"node-persist": "^3.1.0",
Expand Down
6 changes: 6 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { default as axios } from 'axios'
import { cli } from './setup';
import { collections, generateCollections } from './collections';
import { setUpExpressApp, setupAuthenticationLayer, setupRefocusDisengageMiddleware, setupApiDocs, setupSwaggerStatsMiddleware, setupMediaMiddleware, app, setupSocketServer, server, setupBotPressHandler, setupTwilioCompatibleWebhook, enableCORSRequests } from './server';
import localtunnel from 'localtunnel';

let checkUrl = (s : any) => (typeof s === "string") && isUrl(s);

Expand Down Expand Up @@ -166,6 +167,11 @@ async function start() {
spinner.succeed(`\n• Listening on port ${PORT}!`);
await ready({...cliConfig, ...createConfig, ...client.getSessionInfo(), hostAccountNumber: await client.getHostNumber()});
});
if(cliConfig.tunnel) {
spinner.info(`\n• Setting up external tunnel`);
const tunnel = await localtunnel({ port: PORT });
spinner.succeed(`\n\t${terminalLink('External address', tunnel.url)}`)
}
const apiDocsUrl = cliConfig.apiHost ? `${cliConfig.apiHost}/api-docs/ ` : `${cliConfig.host.includes('http') ? '' : 'http://'}${cliConfig.host}:${PORT}/api-docs/ `;
const link = terminalLink('API Explorer', apiDocsUrl);
if (cliConfig && cliConfig.generateApiDocs) spinner.succeed(`\n\t${link}`)
Expand Down
5 changes: 5 additions & 0 deletions src/cli/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ const optionList:
type: Boolean,
description: "Don't validate webhook URLs. Enables use of non-FQDNs."
},
{
name: 'tunnel',
type: Boolean,
description: "Expose a tunnel to your EASY API session - this is for testing and it is unsecured."
},
{
name: 'help',
description: 'Print this usage guide.'
Expand Down

0 comments on commit bc60394

Please sign in to comment.