-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.js
More file actions
33 lines (28 loc) · 847 Bytes
/
server.js
File metadata and controls
33 lines (28 loc) · 847 Bytes
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
const http = require("http");
const config = require("./config");
const { fetchViewsCountAndFollowers } = require("./scraper");
const { generateSvg } = require("./svg-generator");
const server = http.createServer(async (req, res) => {
if (req.url === "/favicon.ico") {
res.writeHead(404);
res.end();
return;
}
try {
const { viewsCount, followersCount } = await fetchViewsCountAndFollowers();
const svg = generateSvg(viewsCount, followersCount, config.blogUrl);
res.writeHead(200, {
"Content-Type": "image/svg+xml",
"Cache-Control": "no-cache, no-store, must-revalidate",
Pragma: "no-cache",
Expires: 0
});
res.end(svg);
} catch (err) {
console.error(err);
}
});
const PORT = config.port;
server.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});