Skip to content

Commit

Permalink
force internalApiUrl for pics if API returned backend_host
Browse files Browse the repository at this point in the history
  • Loading branch information
boogheta committed Jul 24, 2024
1 parent 0b34a96 commit 009d447
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/buildImages.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ exports.createDonut = async function (imageFileName, member, baseImageFolder) {
return donutFileName;
};

const backendHost = process.env.BACKEND_HOST || "localhost";
const internalApiUrl = process.env.INTERNAL_API_URL || "http://localhost:8000";

exports.loadImages = async function (member, imageFolder) {
try {
if (member.avatar) {
let response = await fetch(member.avatar);
let imageUrl = member.avatar;
if (imageUrl.includes(backendHost))
imageUrl = imageUrl.replace(/^https?:\/\/[^\/]*\//, internalApiUrl + "/");
let response = await fetch(imageUrl);
const contentType = response.headers.get("content-type");
if (validImageTypes.includes(contentType)) {
const imageFileName =
Expand All @@ -74,7 +80,12 @@ exports.loadImages = async function (member, imageFolder) {
await createImageFile(response, imagePath);
return imageFileName;
}
return "";
console.log(
"There was a problem while building",
member.slug + "'s",
"image from ",
imageUrl
);
}
return "";
} catch (error) {
Expand Down

0 comments on commit 009d447

Please sign in to comment.