Added Access-Control-Allow-Origin: * to image assets (#17115)

refs https://ghost.slack.com/archives/C025584CA/p1687506966658799
refs https://ghost.slack.com/archives/C04TMVA1D7A/p1687426009256949

This change is required because we otherwise hit CORS issues when admin
tries to load an image and calculate the average color (to determine the
text color).
This commit is contained in:
Simon Backx 2023-06-23 11:10:48 +02:00 committed by GitHub
parent 55b7bef9ad
commit 018f97e679
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,6 +46,8 @@ function createPublicFileMiddleware(location, file, mime, maxAge) {
// send image files directly and let express handle content-length, etag, etc
if (mime.match(/^image/)) {
// In admin we need to read images and calculate the average color (blocked by CORS otherwise)
res.setHeader('Access-Control-Allow-Origin', '*');
return res.sendFile(filePath, (err) => {
if (err && err.status === 404) {
// ensure we're triggering basic asset 404 and not a templated 404