-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
57 lines (43 loc) · 1.35 KB
/
index.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const express = require('express');
const http = require('http');
const { argv } = require('yargs');
const { makeUrl } = require('./utils');
const httpHostname = argv.hostname || process.env.HOSTNAME || '127.0.0.1';
const httpPort = argv.port || process.env.PORT || 3000;
const app = express();
var server = http.createServer(app);
const {
pocketAuthCode,
pocketAuthCallback,
} = require('./pocketAuth');
app.get('/', (req, res) => {
const authData = req.app.locals.auth || {};
let nextUrl = '/pocket/auth';
const requestAuth = (path, productName) => {
// return res.redirect(nextUrl);
return res.send(`<a href="${nextUrl}">Login in ${productName}</a>`);
}
if (!authData.pocket) {
requestAuth('/pocket/auth', 'Pocket');
} else if (!authData.raindrop) {
requestAuth('/raindrop/auth', 'RainDrop');
} else {
res.send('Success!');
}
return res;
});
app.get('/pocket/auth', pocketAuthCode);
app.get('/pocket/callback', pocketAuthCallback);
server.listen(httpPort, httpHostname);
server.on('listening', async () => {
const { port, address } = server.address();
const url = makeUrl({ port, hostname: address });
// eslint-disable-next-line no-console
console.log(`Open page ${url}`);
if (argv.open !== false) {
const open = require('opn');
const browser = open(url).then(() => {
process.exit(0);
});
}
});