Skip to content

Commit

Permalink
Merge pull request #321 from ayuki-joto/fix/clouf-formation-cloud-front
Browse files Browse the repository at this point in the history
fix url & remove OriginPath
  • Loading branch information
ayuki-joto authored Jan 17, 2022
2 parents 7af3553 + 5111f9b commit e5a46a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .cloudformation/cloud_front.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Resources:
Principal:
AWS: !Sub "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${OriginAccessIdentity}"
Action: "s3:GetObject"
Resource: !Sub "arn:aws:s3:::${AppEnvironment}-cfj-decidim/uploads/decidim/*"
Resource: !Sub "arn:aws:s3:::${AppEnvironment}-cfj-decidim/*"


# ------------------------------------------------------------#
Expand Down Expand Up @@ -107,7 +107,6 @@ Resources:
OriginReadTimeout: 60
- Id: !Sub "${AppEnvironment}-cfj-decidim.s3.ap-northeast-1.amazonaws.com"
DomainName: !Sub "${AppEnvironment}-cfj-decidim.s3.ap-northeast-1.amazonaws.com"
OriginPath: /uploads/decidim
S3OriginConfig:
OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${OriginAccessIdentity}"
DefaultCacheBehavior:
Expand Down
18 changes: 13 additions & 5 deletions app/uploaders/decidim/application_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ def store_dir

# Overwrite: If the content block is in preview mode, then we show the
# URL using the asset_host domain
def url(*)
encoded_path = encode_path(path)
if asset_host.respond_to? :call
"#{asset_host.call(self)}/#{encoded_path}"
def url(*args)
if path.nil?
default_url(*args)
else
"#{asset_host}/#{encoded_path}"
encoded_path = encode_path(path.sub(File.expand_path(root), ""))
if (host = asset_host)
if host.respond_to? :call
"#{host.call(self)}/#{encoded_path}"
else
"#{host}/#{encoded_path}"
end
else
(base_path || "") + encoded_path
end
end
end

Expand Down

0 comments on commit e5a46a8

Please sign in to comment.