Skip to content

Commit

Permalink
feat(Storage): S3 bucket instead of EC2 storage for images and thumbn…
Browse files Browse the repository at this point in the history
…ails (#17)

* feat(s3): default plugin config + no credentials patch
---------

Co-authored-by: Nathan Agez <nathan.agez@gmail.com>
  • Loading branch information
mezzLMC and nathanagez authored Dec 1, 2023
1 parent 6c4efbe commit 810581e
Show file tree
Hide file tree
Showing 5 changed files with 1,183 additions and 53 deletions.
71 changes: 42 additions & 29 deletions config/middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
export default [
'strapi::errors',
{
name: "strapi::security",
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
"connect-src": ["'self'", "https:"],
"img-src": ["'self'", "data:", "blob:", "*"],
"media-src": ["'self'", "data:", "blob:", "*"],
"default-src":["'self'"],
"script-src": ["'self'", "'unsafe-inline'"],
upgradeInsecureRequests: null,
export default ({ env }) => (
[
'strapi::errors',
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': [
"'self'",
'data:',
'blob:',
'market-assets.strapi.io',
env('AWS_BUCKET_ENDPOINT'),

],
'media-src': [
"'self'",
'data:',
'blob:',
'market-assets.strapi.io',
env('AWS_BUCKET_ENDPOINT'),
],
upgradeInsecureRequests: null,
},
},
},
},
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
{
name: 'strapi::favicon',
config: {
path: './src/admin/extensions/trackit.png'
},
},
},
'strapi::cors',
'strapi::poweredBy',
'strapi::logger',
'strapi::query',
'strapi::body',
'strapi::session',
{
name: 'strapi::favicon',
config: {
path: './src/admin/extensions/trackit.png'
},
},
'strapi::public',
];
'strapi::public',
]
);
52 changes: 36 additions & 16 deletions config/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
export default {
// ...
'cloudfront-metrics': {
enabled: true,
resolve: './src/plugins/cloudfront-metrics'
},
'custom-selects': {
enabled: true,
resolve: './src/plugins/custom-selects'
},
'docusaurus': {
enabled: true,
resolve: './src/plugins/docusaurus'
},
// ...
}
export default async ({ env }) => {

return {
upload: {
config: {
provider: 'aws-s3',
providerOptions: {
s3Options: {
region: env('AWS_REGION'),
params: {
ACL: 'private', // <== set ACL to private
Bucket: env('AWS_BUCKET'),
},
},
},
actionOptions: {
upload: {},
uploadStream: {},
delete: {},
},
},
},
'cloudfront-metrics': {
enabled: true,
resolve: './src/plugins/cloudfront-metrics'
},
'custom-selects': {
enabled: true,
resolve: './src/plugins/custom-selects'
},
'docusaurus': {
enabled: true,
resolve: './src/plugins/docusaurus'
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@strapi/plugin-documentation": "4.12.0",
"@strapi/plugin-i18n": "4.12.0",
"@strapi/plugin-users-permissions": "4.12.0",
"@strapi/provider-upload-aws-s3": "^4.15.4",
"@strapi/strapi": "4.12.0",
"async_hooks": "^1.0.0",
"chart.js": "^4.3.3",
Expand Down
13 changes: 13 additions & 0 deletions patches/@strapi+provider-upload-aws-s3+4.15.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/@strapi/provider-upload-aws-s3/dist/index.js b/node_modules/@strapi/provider-upload-aws-s3/dist/index.js
index 6cec5cd..817ce80 100644
--- a/node_modules/@strapi/provider-upload-aws-s3/dist/index.js
+++ b/node_modules/@strapi/provider-upload-aws-s3/dist/index.js
@@ -69,7 +69,7 @@ const extractCredentials = (options) => {
secretAccessKey: options.s3Options.credentials.secretAccessKey
};
}
- throw new Error("Couldn't find AWS credentials.");
+ return undefined;
};
const assertUrlProtocol = (url) => {
return /^\w*:\/\//.test(url);
Loading

0 comments on commit 810581e

Please sign in to comment.