Created
April 21, 2021 11:37
-
-
Save rafaelquines/0768b3a4e6244438480e540d69172d03 to your computer and use it in GitHub Desktop.
Ngrok + Serverless Offline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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