Skip to content

Instantly share code, notes, and snippets.

@rafaelquines
Created April 21, 2021 11:37
Show Gist options
  • Save rafaelquines/0768b3a4e6244438480e540d69172d03 to your computer and use it in GitHub Desktop.
Save rafaelquines/0768b3a4e6244438480e540d69172d03 to your computer and use it in GitHub Desktop.
Ngrok + Serverless Offline
npm i -D ngrok
if (process.env.IS_OFFLINE) {
const ngrok = require('ngrok');
let ngrokUrl = await Environment.getNgrokUrl();
if (!ngrokUrl) {
ngrokUrl = await ngrok.connect(3000);
}
return {
replyUrl: `${ngrokUrl}/api/v1/...`,
statusUrl: `${ngrokUrl}/api/v1/...`,
};
}
private static getNgrokUrl = async (): Promise<string> => {
try {
const response = await axios.get('http://localhost:4040/api/tunnels');
const httpsUrl = response.data.tunnels.find((t) => t.proto === 'https');
return httpsUrl ? httpsUrl.public_url : null;
} catch (err) {
return null;
}
}
serverless.yaml:
webpack:
webpackConfig: ./webpack.config.js
includeModules:
forceExclude:
- ngrok
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment