From 35def8696553cae9634012fb5a6bcb9f012aa6ff Mon Sep 17 00:00:00 2001 From: Iacami Gevaerd Date: Fri, 3 Nov 2023 10:34:54 -0300 Subject: [PATCH] default to webp; stream response for progressive rendering also: deploy when pushing "straging" branch along with "develop" --- .github/workflows/deploy-staging.yml | 2 +- app.js | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index ab92652..0ee8179 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -2,7 +2,7 @@ name: Publish to dockerhub and perform a deploy on cloud run on: push: - branches: ["develop"] + branches: ["develop", "staging"] jobs: build-and-push-image: diff --git a/app.js b/app.js index 778ee5d..10e858b 100644 --- a/app.js +++ b/app.js @@ -14,7 +14,7 @@ const getImage = (path) => status: r.status, })); const getFormat = (webp, avif) => { - return avif ? "avif" : webp ? "webp" : "jpeg"; + return webp ? "webp" : avif ? "avif" : "jpeg"; }; app.get("/healthy", (req, res) => { @@ -45,16 +45,16 @@ app.get("*", async (req, res) => { .send("upstream server did not respond with a valid status code"); } - const processedImage = await sharp(data) - .rotate() - .resize({ width, height }) - .toFormat(format, { quality }); - - return res + res .set("Cache-Control", "public, max-age=15552000") .set("Vary", "Accept") - .type(`image/${format}`) - .send(await processedImage.toBuffer()); + .type(`image/${format}`); + + sharp(data) + .rotate() + .resize({ width, height }) + .toFormat(format, { effort: 3, quality, progressive: true }) + .pipe(res); } catch (e) { return res.status(500).send(JSON.stringify(e)); }