-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
34 lines (31 loc) · 1002 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const config = require('./config');
const http = require('http');
const url = require('url');
function requestHandler(req, res) {
const parsedUrl = url.parse(req.url, true);
if (req.method === 'GET' &&
parsedUrl.pathname === '/callback' &&
parsedUrl.query.oauth_token &&
parsedUrl.query.oauth_verifier &&
parsedUrl.query.id) {
this.emit(
'auth',
parsedUrl.query.id,
parsedUrl.query.oauth_token,
parsedUrl.query.oauth_verifier
);
res.end('You can close this page now. Forwardr will submit your authorization soon.');
return;
}
res.end('Something going wrong. Contact me – @pashutk in Telegram.');
}
const createServer = async () => await new Promise((resolve, reject) => {
const server = http.createServer(requestHandler);
server.listen(config.FORWARDR_SERVER_PORT, function() {
console.log(`Server listen on ${config.FORWARDR_SERVER_PORT}`);
resolve(server);
});
});
module.exports = {
createServer
}