-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (43 loc) · 1.07 KB
/
server.js
File metadata and controls
54 lines (43 loc) · 1.07 KB
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
const assert = require('assert');
// If in development
if (process.env.NODE_ENV !== 'production') {
assert(
require('dotenv').config({ silent: true }),
"Don't forget the .env file"
);
}
const debug = require('debug')('App');
debug('App running in debug mode');
const scrapper = require('./mangaHereTransformer');
const RSS = require('rss');
const server = require('http').createServer((req, res) => {
if (req.url !== '/rss') {
res.statusCode = 404;
debug('404');
return res.end(null);
}
debug('processing rss request');
var feed = new RSS({
title: 'MangaHere generated feed',
feed_url: 'http://www.mangahere.co/latest/',
site_url: 'http://www.mangahere.co',
ttl: '5'
});
scrapper()((err, data) => {
if (err) {
res.statusCode = 500;
return res.end();
}
data.forEach(_manga =>
feed.item({
title: _manga.title,
url: _manga.link
})
);
res.end(feed.xml());
});
});
const port = process.env.PORT || 5000;
server.listen(port, () => {
debug('App listening on port ' + port);
});