Skip to content

Instantly share code, notes, and snippets.

@vgrichina

vgrichina/callback.js

Last active Jul 12, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.