Open14

Blazor WebAssembly

kaorumorikaorumori

ZIP圧縮

using System.IO.Compression;

public byte[] ZippedImages()
{
    MemoryStream stream = new();
    using (ZipArchive archive = new(stream, ZipArchiveMode.Create))
    {
        foreach (var image in images)
        {
            ZipArchiveEntry entry = archive.CreateEntry(image.Key);
            using (BinaryWriter writer = new(entry.Open()))
            {
                writer.Write(image.Value);
            }
        }
    }
    return stream.ToArray();
}
kaorumorikaorumori

S3+CloudFrontにデプロイ

S3

バケットを作成

パブリックアクセスをすべて ブロックをオフにしてバケットを作成します。

バケットポリシー

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::<BucketName>/*"
        }
    ]
}

静的ウェブサイトホスティング

プロパティ > 静的ウェブサイトホスティング で 静的ウェブサイトホスティングを有効にします。

インデックスドキュメントエラードキュメントindex.htmlを指定します。

CloudFront

https://qiita.com/right1121/items/8e5fec1f109fdd5ba152

カスタムエラーレスポンス

カスタムエラーレスポンスを作成して403だったときに/を指定します。

https://dev.classmethod.jp/articles/s3-cloudfront-spa-angular-403-access-denied/

kaorumorikaorumori

This browser does not support WebAssembly. のエラーハンドリング

index.html
window.onerror = (message, file, lineNo, colNo, error) => {
    console.warn(message);
}

https://qiita.com/grapswiz/items/71f14e73820e352c1fa3

unhandledrejectionは利用していないが、発生するエラーによっては利用する必要があるかもしれない。

kaorumorikaorumori

PublishSPAforGitHubPages.Build の利用

dotnet add package PublishSPAforGitHubPages.Build

GHPagesBaseを指定

dotnet publish -c Release -p GHPages=true -p GHPagesBase=/