From 4199d0596f1bb4f46525fc5f2fe04048c1f0c5f2 Mon Sep 17 00:00:00 2001 From: earphone-jack Date: Mon, 11 Dec 2023 12:59:01 +0000 Subject: [PATCH] Build output for commit 405f0bc7230cbcfec2f5cf727282f5e9a1f1c2c7 --- dist/app.js | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/dist/app.js b/dist/app.js index cf4846f..9d30077 100644 --- a/dist/app.js +++ b/dist/app.js @@ -13,10 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = __importDefault(require("express")); -const got_1 = __importDefault(require("got")); -const http_1 = __importDefault(require("http")); -const https_1 = __importDefault(require("https")); const node_cache_1 = __importDefault(require("node-cache")); +const node_fetch_1 = __importDefault(require("node-fetch")); const app = (0, express_1.default)(); const cache = new node_cache_1.default(); function createBadge(badge) { @@ -26,15 +24,14 @@ function createBadge(badge) { if (cache.has(url.toString())) { return cache.get(url.toString()); } - const response = (yield (0, got_1.default)(url)).body; - cache.set(url.toString(), response); - return response; + const response = yield (0, node_fetch_1.default)(url); + const body = yield response.text(); + cache.set(url.toString(), body); + return body; }); } -app.use(express_1.default.static(__dirname + '/frontend/build', { - index: false -})); -app.get('/*', (req, res) => { +app.use(express_1.default.static(__dirname + '/frontend/build', { index: false })); +app.get('/*', (req, res) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c, _d; if (!("app" in req.query)) { return res.status(200).sendFile(__dirname + '/frontend/build/index.html'); @@ -63,24 +60,12 @@ app.get('/*', (req, res) => { } else if (statusCode <= 399 && statusCode >= 300) { } - res.setHeader('Content-type', 'image/svg+xml'); - res.status(200).send(yield createBadge(badge)); + createBadge(badge) + .then(badge => res.setHeader('Content-type', 'image/svg+xml').status(200).send(badge)) + .catch(_ => res.status(500).send('Internal Server Error. Please open an issue at vercel-badge/issues.')); }); - try { - https_1.default.get("https://" + url, (response) => __awaiter(void 0, void 0, void 0, function* () { - var statusCode = response.statusCode; - yield handleRequest(statusCode); - })).on('error', () => { - http_1.default.get("http://" + url, (response) => __awaiter(void 0, void 0, void 0, function* () { - var statusCode = response.statusCode; - yield handleRequest(statusCode); - })).on('error', () => { - handleRequest(404); - }); - }); - } - catch (_e) { - res.status(500).send('Internal Server Error. Please open an issue at vercel-badge/issues.'); - } -}); + (0, node_fetch_1.default)(`http://${url}`) + .then(response => handleRequest(response.status)) + .catch(_ => handleRequest()); +})); exports.default = app;