From e588463b497fa0d1463edfe849edf55fd3a186da Mon Sep 17 00:00:00 2001 From: NeoNexus DeMortis Date: Tue, 5 Dec 2023 21:51:02 -0600 Subject: [PATCH 1/5] Create package.json --- examples/sails/package.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 examples/sails/package.json diff --git a/examples/sails/package.json b/examples/sails/package.json new file mode 100644 index 00000000..f2798f35 --- /dev/null +++ b/examples/sails/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "@ngrok/ngrok": "^0.*", + "sails": "^1.*" + } +} From 889d7b337a202ad4d0856112f5565d33f8aedf47 Mon Sep 17 00:00:00 2001 From: NeoNexus DeMortis Date: Tue, 5 Dec 2023 22:25:28 -0600 Subject: [PATCH 2/5] Created ngrok.js --- examples/sails/ngrok.js | 103 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 examples/sails/ngrok.js diff --git a/examples/sails/ngrok.js b/examples/sails/ngrok.js new file mode 100644 index 00000000..45aef397 --- /dev/null +++ b/examples/sails/ngrok.js @@ -0,0 +1,103 @@ +#!/usr/bin/env node + +/** + * + * Original version of this example can be found here: + * https://github.com/neonexus/sails-react-bootstrap-webpack/blob/release/ngrok.js + * + */ + +/** + * This is the file used to lift Sails, and start Ngrok. + * + * Run it via node: `node ngrok.js` + * Run it directly: `./ngrok.js` (if file is marked as executable) + */ + +const moduleLoader = require('sails/lib/hooks/moduleloader'); +const path = require('path'); +const rc = require('sails/accessible/rc'); +const ngrok = require('@ngrok/ngrok'); +const sails = require('sails'); +const {spawn} = require('child_process'); + +// Load configuration the way Sails would. +moduleLoader({ + config: { + environment: process.env.NODE_ENV || 'development', + paths: { + config: path.join(__dirname, 'config') + } + } +}).loadUserConfig((err, config) => { + if (err) { + console.error(''); + console.error('There was an issue loading user configuration:'); + console.error(''); + console.error(err); + console.error(''); + + return process.exit(1); + } + + // Set Ngrok defaults. These can be overwritten in `config/ngrok.js` or `config/local.js`. + // Basically, this is just a safety net, should one delete the `config/ngrok.js` file. + config = { + ngrok: { + auth: process.env.NGROK_BASIC || undefined, // Basic auth for the Ngrok tunnel. + token: process.env.NGROK_AUTHTOKEN || process.env.NGROK_TOKEN || undefined, // The Ngrok token for your account. + domain: process.env.NGROK_DOMAIN || undefined, // The Ngrok domain to use. + region: process.env.NGROK_REGION || undefined, // Defaults to Global. + port: process.env.PORT || 4242 // The port to start Sails on. + }, + ...config + }; + + ngrok.forward({ + addr: config.ngrok.port, // This is actually the port to we'll use for Sails. Ngrok will handle its own ports. + authtoken: config.ngrok.token, + basic_auth: config.ngrok.auth, // eslint-disable-line + domain: config.ngrok.domain, + region: config.ngrok.region, + schemes: ['HTTPS'] + }).then((listener) => { + let origins; + const ngrokUrl = listener.url(); + + // Add the Ngrok URL to our allowed origins. + if (config.security && config.security.cors && config.security.cors.allowOrigins) { + origins = [...config.security.cors.allowOrigins]; + + if (!config.security.cors.allowOrigins.includes(ngrokUrl)) { + origins.push(ngrokUrl); + } + } else { + origins = [ngrokUrl]; + } + + // Start Sails with some configuration overrides. + sails.lift({ + ...rc('sails'), + port: config.ngrok.port, + security: { + cors: { + allowOrigins: origins + } + } + }, (err) => { + if (err) { + console.error(err); + + return process.exit(1); + } + + // Hurray! We are up and running! + }); + }).catch((e) => { + console.log(''); + console.log('There was an error starting the Ngrok tunnel. Here is the error:'); + console.log(''); + console.log(e.message); + console.log(''); + }); +}); From ae4bd27d6d739e90d6ed07f5c4883d104f78d878 Mon Sep 17 00:00:00 2001 From: NeoNexus DeMortis Date: Tue, 5 Dec 2023 22:26:51 -0600 Subject: [PATCH 3/5] Created ngrok.js --- examples/sails/config/ngrok.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/sails/config/ngrok.js diff --git a/examples/sails/config/ngrok.js b/examples/sails/config/ngrok.js new file mode 100644 index 00000000..68eb2963 --- /dev/null +++ b/examples/sails/config/ngrok.js @@ -0,0 +1,21 @@ +/** + * This file is used to configure the `ngrok.js` script. + */ + +module.exports.ngrok = { + // Set an HTTP basic-auth wall for the app. + auth: process.env.NGROK_BASIC || undefined, // Use a string of 'username:password' style (raw password) + + // Default Ngrok authtoken, to tie to your account. + // https://dashboard.ngrok.com/get-started/your-authtoken + token: process.env.NGROK_AUTHTOKEN || process.env.NGROK_TOKEN || undefined, // NEVER store PRODUCTION secrets in Git-controlled files! + + // The static domain to use for the Ngrok tunnel. Something like: 'running-grey-gazelle.ngrok-free.app' + domain: process.env.NGROK_DOMAIN || undefined, + + // The default region for the Ngrok tunnel. + region: process.env.NGROK_REGION || undefined, + + // The default port to start Sails for the Ngrok tunnel. + port: process.env.PORT || 4242 // Use 4242 instead of 1337, so we can run 2 instances if we want. +}; From 202983d5cdcc4a8a938d5aaeb07f1ecabd3b74d8 Mon Sep 17 00:00:00 2001 From: NeoNexus DeMortis Date: Tue, 5 Dec 2023 22:31:52 -0600 Subject: [PATCH 4/5] Created local.js --- examples/sails/config/local.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/sails/config/local.js diff --git a/examples/sails/config/local.js b/examples/sails/config/local.js new file mode 100644 index 00000000..10b0727e --- /dev/null +++ b/examples/sails/config/local.js @@ -0,0 +1,19 @@ +/** + * Local environment settings + * + * For more information, check out: + * https://sailsjs.com/docs/concepts/configuration/the-local-js-file + */ + +module.exports = { + // Configuration options for ngrok.js script. + ngrok: { + // auth: 'username:notSoSecretPassword', // Uncomment to set a basic-auth user/password for the Ngrok tunnel. Password must be between 8 and 128 characters. + domain: 'my-ngrok-app.ngrok-free.app', + token: '{{my_ngrok_token_here}}', + port: 4242 // This sets Sails' port when running `ngrok.js`. + }, + + // The port to attach the API to. This does NOT affect the `ngrok.js` script. + port: 1337, +}; From 3698036ce87f85182245664e6f4a3f3553384559 Mon Sep 17 00:00:00 2001 From: NeoNexus DeMortis Date: Tue, 5 Dec 2023 22:56:30 -0600 Subject: [PATCH 5/5] Update index.html --- docs/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.html b/docs/index.html index a7e38ba1..9b0ba848 100644 --- a/docs/index.html +++ b/docs/index.html @@ -117,6 +117,7 @@

@ngrok/ngrok

  • Nest.js
  • Next.js
  • Remix
  • +
  • Sails
  • Svelte
  • Typescript
  • Vue
  • @@ -309,4 +310,4 @@

    UpdateRequest

    Generated using TypeDoc

    -
    \ No newline at end of file +