Skip to content

Commit

Permalink
hiding base url
Browse files Browse the repository at this point in the history
  • Loading branch information
enapupe committed Nov 2, 2023
1 parent 78b0b43 commit b1b120a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const sharp = require("sharp");
const app = express();
const PORT = 8080;
const HOST = "0.0.0.0";
const BASE_STORAGE_IMAGE_URL = "https://storage.googleapis.com/openbeta-prod/u";
const BASE_STORAGE_IMAGE_URL = "https://storage.googleapis.com";

const getImage = (path) => fetch(path).then((res) => res.arrayBuffer());
const getFormat = (webp, avif) => {
Expand All @@ -19,7 +19,9 @@ app.get("/healthy", (req, res) => {

app.get("*", async (req, res) => {
try {
const { searchParams, pathname, href } = new URL(req.url.slice(1));
const { searchParams, pathname, href } = new URL(
`${BASE_STORAGE_IMAGE_URL}${req.url}`,
);

if (!/\.(jpe?g|png|gif|webp)$/i.test(pathname)) {
return res.status(400).send("Disallowed file extension");
Expand All @@ -38,6 +40,8 @@ app.get("*", async (req, res) => {
.resize({ width, height })
.toFormat(format, { quality });

console.log(pathname, href);

return res
.set("Cache-Control", "public, max-age=15552000")
.set("Vary", "Accept")
Expand Down

0 comments on commit b1b120a

Please sign in to comment.