I’m currently building a website with React + Vite and Strapi. Strapi loads the images from an s3-Bucket on AWS. Now I got a problem with CORS, because everytime I hover over the images I get the following error:
Sometimes I get the error in the gallery and sometimes in the AboutMe-profilImage-Section. The error does not occur on Safari-Browser. Feel free to look on the website yourself and check network etc.
Setup and settings I already have:
S3-Cors-Settings:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]
Frontend:
https://github.com/EnXan/Frontend-DJ-Service-Musicland.git
Backend plugin.js Strapi
const parse = require('pg-connection-string').parse;
const config = parse(process.env.DATABASE_URL);
module.exports = ({ env }) => ({
upload: {
config: {
provider: 'aws-s3',
providerOptions: {
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_ACCESS_SECRET,
},
region: process.env.AWS_REGION,
baseUrl: `https://s3.${process.env.AWS_REGION}.amazonaws.com/${process.env.AWS_BUCKET_NAME}`, // This line sets the custom url format
params: {
signedUrlExpires: process.env.AWS_SIGNED_URL_EXPIRES || 15 * 60,
Bucket: process.env.AWS_BUCKET_NAME,
},
},
actionOptions: {
upload: {},
uploadStream: {},
delete: {},
},
},
},
connection: {
client: 'postgres',
connection: {
host: config.host,
port: config.port,
database: config.database,
user: config.user,
password: config.password,
ssl: {
rejectUnauthorized: false
},
},
debug: false,
},
});
Backend middleware.js STRAPI:
const compression = require('compression');
const { env } = require('@strapi/utils');
module.exports = [
'strapi::logger',
'strapi::errors',
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': [
"'self'",
'data:',
'blob:',
'market-assets.strapi.io',
's3.eu-north-1.amazonaws.com',
],
'media-src': [
"'self'",
'data:',
'blob:',
'market-assets.strapi.io',
's3.eu-north-1.amazonaws.com',
],
upgradeInsecureRequests: null,
},
},
},
},
'strapi::cors',
'strapi::poweredBy',
'strapi::query',
'strapi::body',
'strapi::session',
'strapi::favicon',
'strapi::public',
{
name: 'strapi::compression',
config: {
br: true,
gzip: true,
threshold: 1024,
},
},
];