Skip to content

Commit 35def86

Browse files
committed
default to webp; stream response for progressive rendering
also: deploy when pushing "straging" branch along with "develop"
1 parent 40f6712 commit 35def86

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

.github/workflows/deploy-staging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Publish to dockerhub and perform a deploy on cloud run
22

33
on:
44
push:
5-
branches: ["develop"]
5+
branches: ["develop", "staging"]
66

77
jobs:
88
build-and-push-image:

app.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getImage = (path) =>
1414
status: r.status,
1515
}));
1616
const getFormat = (webp, avif) => {
17-
return avif ? "avif" : webp ? "webp" : "jpeg";
17+
return webp ? "webp" : avif ? "avif" : "jpeg";
1818
};
1919

2020
app.get("/healthy", (req, res) => {
@@ -45,16 +45,16 @@ app.get("*", async (req, res) => {
4545
.send("upstream server did not respond with a valid status code");
4646
}
4747

48-
const processedImage = await sharp(data)
49-
.rotate()
50-
.resize({ width, height })
51-
.toFormat(format, { quality });
52-
53-
return res
48+
res
5449
.set("Cache-Control", "public, max-age=15552000")
5550
.set("Vary", "Accept")
56-
.type(`image/${format}`)
57-
.send(await processedImage.toBuffer());
51+
.type(`image/${format}`);
52+
53+
sharp(data)
54+
.rotate()
55+
.resize({ width, height })
56+
.toFormat(format, { effort: 3, quality, progressive: true })
57+
.pipe(res);
5858
} catch (e) {
5959
return res.status(500).send(JSON.stringify(e));
6060
}

0 commit comments

Comments
 (0)