Skip to content

Instantly share code, notes, and snippets.

@mahboubii
Created January 6, 2021 14:40
Show Gist options
  • Save mahboubii/aaa9a4293f5a804f6de1be7c1317cab3 to your computer and use it in GitHub Desktop.
Save mahboubii/aaa9a4293f5a804f6de1be7c1317cab3 to your computer and use it in GitHub Desktop.
const express = require('express');
const bodyParser = require('body-parser');
const localtunnel = require('localtunnel');
const PORT = 8000;
const app = express();
// body-parser parsed the body to a json object for us, it also store the rawBody so later we can check the request integrity
app.use(bodyParser.json({ verify: (req, res, buf) => (req.rawBody = buf) }));
app.get('/', (req, res) => {
return res.status(200).json({ message: 'API is live!' });
});
const setupTunnelAndWebhook = async () => {
const { url } = await localtunnel({ port: PORT });
console.log(`Server running remotely in ${url}`);
};
app.listen(PORT, (err) => {
if (err) throw err;
console.log(`Server running in http://127.0.0.1:${PORT}`);
setupTunnelAndWebhook();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment