Skip to content

Commit bc60394

Browse files
committed
✨ CLI: Expose EASY API with --tunnel #2314
1 parent f0bf4bc commit bc60394

File tree

4 files changed

+85
-35
lines changed

4 files changed

+85
-35
lines changed

package-lock.json

Lines changed: 71 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "4.23.18",
44
"licenseCheckUrl": "https://openwa.dev/license-check",
55
"brokenMethodReportUrl": "https://openwa.dev/report-bm",
6-
"patches": "https://cdn.openwa.dev/patches.json",
6+
"patches": "http://127.0.0.1:5503/functions/patches.json",
77
"stickerUrl": "https://sticker-api.openwa.dev",
88
"description": " 💬 🤖 The most reliable NodeJS whatsapp library for chatbots with advanced features.",
99
"main": "dist/index.js",
@@ -69,6 +69,7 @@
6969
"@types/express": "^4.17.11",
7070
"@types/fs-extra": "^9.0.11",
7171
"@types/line-reader": "0.0.34",
72+
"@types/localtunnel": "^2.0.1",
7273
"@types/marked": "^3.0.0",
7374
"@types/mime-types": "^2.1.0",
7475
"@types/node": "^16.0.0",
@@ -124,6 +125,7 @@
124125
"image-type": "^4.1.0",
125126
"is-url-superb": "^5.0.0",
126127
"json5": "^2.2.0",
128+
"localtunnel": "^2.0.2",
127129
"lodash.uniq": "^4.5.0",
128130
"meow": "^9.0.0",
129131
"node-persist": "^3.1.0",

src/cli/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { default as axios } from 'axios'
66
import { cli } from './setup';
77
import { collections, generateCollections } from './collections';
88
import { setUpExpressApp, setupAuthenticationLayer, setupRefocusDisengageMiddleware, setupApiDocs, setupSwaggerStatsMiddleware, setupMediaMiddleware, app, setupSocketServer, server, setupBotPressHandler, setupTwilioCompatibleWebhook, enableCORSRequests } from './server';
9+
import localtunnel from 'localtunnel';
910

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

@@ -166,6 +167,11 @@ async function start() {
166167
spinner.succeed(`\n• Listening on port ${PORT}!`);
167168
await ready({...cliConfig, ...createConfig, ...client.getSessionInfo(), hostAccountNumber: await client.getHostNumber()});
168169
});
170+
if(cliConfig.tunnel) {
171+
spinner.info(`\n• Setting up external tunnel`);
172+
const tunnel = await localtunnel({ port: PORT });
173+
spinner.succeed(`\n\t${terminalLink('External address', tunnel.url)}`)
174+
}
169175
const apiDocsUrl = cliConfig.apiHost ? `${cliConfig.apiHost}/api-docs/ ` : `${cliConfig.host.includes('http') ? '' : 'http://'}${cliConfig.host}:${PORT}/api-docs/ `;
170176
const link = terminalLink('API Explorer', apiDocsUrl);
171177
if (cliConfig && cliConfig.generateApiDocs) spinner.succeed(`\n\t${link}`)

src/cli/setup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ const optionList:
229229
type: Boolean,
230230
description: "Don't validate webhook URLs. Enables use of non-FQDNs."
231231
},
232+
{
233+
name: 'tunnel',
234+
type: Boolean,
235+
description: "Expose a tunnel to your EASY API session - this is for testing and it is unsecured."
236+
},
232237
{
233238
name: 'help',
234239
description: 'Print this usage guide.'

0 commit comments

Comments
 (0)