Skip to content

Instantly share code, notes, and snippets.

@vgrichina
Last active July 12, 2019 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrichina/cfa393ecb3340779bf42f5a0c02d592f to your computer and use it in GitHub Desktop.
Save vgrichina/cfa393ecb3340779bf42f5a0c02d592f to your computer and use it in GitHub Desktop.
Spin up temporary webserver to handle callback from browser
const http = require('http');
const url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
try {
let parsedUrl = url.parse(req.url, true);
console.log('query', parsedUrl.query);
let accountId = parsedUrl.query.account_id;
res.end('Much success, you can close window now');
console.log('Account ID:', accountId);
// doSomething(accountId);
server.close();
} catch (e) {
console.log('Unexpected error: ', e);
res.statusCode = 400;
res.end('It\'s a scam!');
return;
}
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment