Skip to content

Commit

Permalink
Merge pull request novuhq#2513 from JoeyEamigh/2512-branded-image-cdn
Browse files Browse the repository at this point in the history
feat: Support serving uploaded files from CDN
  • Loading branch information
scopsy authored Jan 17, 2023
2 parents 1b4797b + fac16a0 commit 5d4f2c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions apps/api/src/.example.env
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ S3_REGION=us-east-1
AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test
NEW_RELIC_ENABLED=false
CDN_URL=

GLOBAL_CONTEXT_PATH=
API_CONTEXT_PATH=
Expand Down
17 changes: 8 additions & 9 deletions apps/api/src/app/shared/services/storage/storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ export class S3StorageService implements StorageService {

const signedUrl = await getSignedUrl(this.s3, command, { expiresIn: 3600 });
const parsedUrl = new URL(signedUrl);
const path = process.env.CDN_URL ? `${process.env.CDN_URL}/${key}` : `${parsedUrl.origin}${parsedUrl.pathname}`;

return {
signedUrl,
path: `${parsedUrl.origin}${parsedUrl.pathname}`,
};
return { signedUrl, path };
}
}

Expand Down Expand Up @@ -159,11 +157,11 @@ export class GCSStorageService implements StorageService {
});

const parsedUrl = new URL(signedUrl);
const path = process.env.CDN_URL
? `${process.env.CDN_URL}/${key}`
: `${process.env.GCS_DOMAIN}${parsedUrl.pathname}`;

return {
signedUrl,
path: `${process.env.GCS_DOMAIN}${parsedUrl.pathname}`,
};
return { signedUrl, path };
}
}

Expand Down Expand Up @@ -233,13 +231,14 @@ export class AzureBlobStorageService implements StorageService {
).toString();

const signedUrl = `${blobClient.url}?${blobSAS}`;
const path = process.env.CDN_URL ? `${process.env.CDN_URL}/${key}` : `${blobClient.url}`;
const additionalHeaders = {
'x-ms-blob-type': 'BlockBlob',
};

return {
signedUrl,
path: `${blobClient.url}`,
path,
additionalHeaders: additionalHeaders,
};
}
Expand Down

0 comments on commit 5d4f2c5

Please sign in to comment.