-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (42 loc) · 1.37 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
const express = require('express');
const flatten = require('./lib/flatten');
function getFullUrl(req) {
return `${req.protocol}://${req.get('host')}${req.originalUrl}`;
}
module.exports = function server(port) {
const app = express();
app.get('/html/:token', (req, res) => {
const token = req.params.token;
if (!token) throw new Error('oauth token not provided');
const opts = req.query;
//TODO - write function to sanitize query opts
if (opts.minSize) opts.minSize = Number(opts.minSize);
flatten(token, opts)
.then((result) => {
//console.log('result', result)
const view = `${__dirname}/views/html.jade`;
const locals = {};
locals.files = result;
res.render(view, locals);
});
});
app.get('/rss/:token', (req, res) => {
const token = req.params.token;
if (!token) throw new Error('oauth token not provided');
const opts = req.query;
//TODO - write function to sanitize query opts
if (opts.minSize) opts.minSize = Number(opts.minSize);
flatten(token, opts)
.then((result) => {
//console.log('result', result)
const view = `${__dirname}/views/rss.jade`;
const locals = {};
locals.feedUrl = getFullUrl(req);
locals.files = result;
res.render(view, locals);
});
});
//start server
app.listen(port);
console.log(`Server started on port ${port}`);
};