github-readme-stats/api/pin.js
2020-07-11 23:20:42 +05:30

21 lines
518 B
JavaScript

require("dotenv").config();
const { renderError } = require("../src/utils");
const fetchRepo = require("../src/fetchRepo");
const renderRepoCard = require("../src/renderRepoCard");
module.exports = async (req, res) => {
const { username, repo } = req.query;
let repoData;
res.setHeader("Content-Type", "image/svg+xml");
try {
repoData = await fetchRepo(username, repo);
} catch (err) {
console.log(err);
return res.send(renderError(err.message));
}
res.send(renderRepoCard(repoData));
};