vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.67k stars 1.01k forks source link

Absolute URL's for S3 + pre-generated sizes #2101

Open martijnvdbrug opened 1 year ago

martijnvdbrug commented 1 year ago

Is your feature request related to a problem? Please describe. It would be nice if we could use the S3 asset plugin, and also leverage the CDN capabilities of S3. Currently the plugin routes all assets through the Vendure server.

Describe the solution you'd like I would like to be able to configure the S3 plugin to use absolute URL's to S3 buckets. When we use absolute URL's it would also be nice to set some sizes that will be pregenerated, because we will not use the Asset Server anymore in this setup:

 storageStrategyFactory: configureS3AssetStorage({
      bucket: 'my-s3-bucket',
      credentials: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
      },
      useCdnUrls: true,
      pregeneratedSizes: [
         {
            name: "thumbnail",
            width: 500,
            height: 500,
            format: "webp"
         }
      ]
    }),

This would then add thumbnail to all Asset Fields

Describe alternatives you've considered

Additional context The google cloud asset storage plugin does something similar: https://github.com/Pinelab-studio/pinelab-vendure-plugins/tree/master/packages/vendure-plugin-google-storage-assets

StampixSMO commented 1 year ago

Would also like to see this, how do you view the integration with the CDN itself (CloudFront)? I.e. which host to point to.

Additionally, I'm kind of assuming that the thumbnail pregenerated size would be the responsibility of the implementer then? Since AFAIK S3 does not have that functionality built-in.

martijnvdbrug commented 1 year ago

Good question, the Google storage plugin constructs the url by prefixing it with 'storage.apis...'. i would expect something similar for this implementation.

Pregeneration should indeed be handled by the S3 implementation

StampixSMO commented 1 year ago

S3 itself does not have a CDN, you need to set up a CloudFront distribution and point it to the S3 bucket. That CF distribution can have any domain you want, so somehow this will need to be configured in this strategy (perfectly fine).

dlhck commented 3 weeks ago

@martijnvdbrug S3 does not have any CDN capabilities. These are provided by AWS CloudFront. Pre-generation would need to happen through Vendure, this could be done through a new feature called "Scheduled Tasks" that we are currently looking at.