Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(database)' == 'PostgreSQL' OR '$(database)' == '') " Include="Aspire.Hosting.PostgreSQL" Version="9.3.1" />
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(database)' == 'MySql' OR '$(database)' == '') " Include="Aspire.Hosting.MySql" Version="9.3.1" />
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(filesStorage)' == 'AzureBlobStorage' OR '$(filesStorage)' == '') " Include="Aspire.Hosting.Azure.Storage" Version="9.3.1" />
<PackageVersion Condition=" ('$(aspire)' == 'true' OR '$(aspire)' == '') AND ('$(filesStorage)' == 'S3' OR '$(filesStorage)' == '') " Include="CommunityToolkit.Aspire.Hosting.Minio" Version="9.5.1-beta.308" />
<PackageVersion Include="Microsoft.Extensions.Http.Resilience" Version="9.6.0" />
<PackageVersion Include="Microsoft.Extensions.ServiceDiscovery" Version="9.3.1" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
Expand Down Expand Up @@ -84,7 +85,7 @@
<PackageVersion Condition=" '$(database)' == 'SqlServer' OR '$(database)' == '' " Include="EFCore.SqlServer.VectorSearch" Version="9.0.0-preview.2" />
<PackageVersion Condition=" '$(database)' == 'SqlServer' OR '$(database)' == '' " Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.6" />
<PackageVersion Condition=" '$(database)' == 'PostgreSQL' OR '$(database)' == '' " Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.4" />
<PackageVersion Condition=" '$(database)' == 'MySql' OR '$(database)' == '' " Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.2.efcore.9.0.0" />
<PackageVersion Condition=" '$(database)' == 'MySql' OR '$(database)' == '' " Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.3.efcore.9.0.0" />
<PackageVersion Condition=" '$(filesStorage)' == 'AzureBlobStorage' OR '$(filesStorage)' == '' " Include="FluentStorage.Azure.Blobs" Version="5.3.0" />
<PackageVersion Condition=" '$(filesStorage)' == 'S3' OR '$(filesStorage)' == '' " Include="FluentStorage.AWS" Version="5.5.0" />
<PackageVersion Condition=" '$(appInsights)' == 'true' OR '$(appInsights)' == '' " Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.23.0" />
Expand All @@ -111,7 +112,7 @@
<PackageVersion Include="AspNet.Security.OAuth.Apple" Version="9.4.0" />
<PackageVersion Include="AspNet.Security.OAuth.GitHub" Version="9.4.0" />
<PackageVersion Include="Riok.Mapperly" Version="4.2.1" />
<PackageVersion Include="Twilio" Version="7.11.3" />
<PackageVersion Include="Twilio" Version="7.11.4" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="9.0.6" />
<PackageVersion Include="Microsoft.AspNetCore.Authorization" Version="9.0.6" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.6" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,38 @@ public static void AddServerApiProjectServices(this WebApplicationBuilder builde
services.AddSingleton(_ => PhoneNumberUtil.GetInstance());
services.AddSingleton<IBlobStorage>(sp =>
{
//#if (filesStorage == "Local")
var isRunningInsideDocker = Directory.Exists("/container_volume"); // It's supposed to be a mounted volume named /container_volume
var appDataDirPath = Path.Combine(isRunningInsideDocker ? "/container_volume" : Directory.GetCurrentDirectory(), "App_Data");
Directory.CreateDirectory(appDataDirPath);
return StorageFactory.Blobs.DirectoryFiles(appDataDirPath);
//#elif (filesStorage == "AzureBlobStorage")
string ExtractAccountKey(string connectionString)
//#if (filesStorage == "AzureBlobStorage" || filesStorage == "S3")
string GetValue(string connectionString, string key)
{
if (connectionString is "UseDevelopmentStorage=true")
return "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="; // https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=visual-studio%2Cblob-storage#well-known-storage-account-and-key

var parts = connectionString.Split(';');
foreach (var part in parts)
{
if (part.StartsWith("AccountKey="))
return part["AccountKey=".Length..];
if (part.StartsWith($"{key}="))
return part[$"{key}=".Length..];
}
throw new ArgumentException("Invalid connection string: AccountKey not found.");
throw new ArgumentException($"Invalid connection string: '{key}' not found.");
}
//#endif

//#if (filesStorage == "Local")
var isRunningInsideDocker = Directory.Exists("/container_volume"); // It's supposed to be a mounted volume named /container_volume
var appDataDirPath = Path.Combine(isRunningInsideDocker ? "/container_volume" : Directory.GetCurrentDirectory(), "App_Data");
Directory.CreateDirectory(appDataDirPath);
return StorageFactory.Blobs.DirectoryFiles(appDataDirPath);
//#elif (filesStorage == "AzureBlobStorage")
var azureBlobStorageConnectionString = configuration.GetConnectionString("AzureBlobStorageConnectionString")!;
var blobServiceClient = new BlobServiceClient(azureBlobStorageConnectionString);
string accountName = blobServiceClient.AccountName;
string accountKey = ExtractAccountKey(azureBlobStorageConnectionString);
string accountKey = azureBlobStorageConnectionString is "UseDevelopmentStorage=true" ? "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" // https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=visual-studio%2Cblob-storage#well-known-storage-account-and-key
: GetValue(azureBlobStorageConnectionString, "AccountKey");
return StorageFactory.Blobs.AzureBlobStorageWithSharedKey(accountName, accountKey, blobServiceClient.Uri);
//#elif (filesStorage == "S3")
// Checkout https://github.com/robinrodricks/FluentStorage for more S3 providers samples such as Digital Ocean's Spaces Object Storage, AWS, etc.
// Run through docker using `docker run -d -p 9000:9000 -p 9001:9001 -e "MINIO_ROOT_USER=minioadmin" -e "MINIO_ROOT_PASSWORD=minioadmin" quay.io/minio/minio server /data --console-address ":9001"`
// Open MinIO console at http://127.0.0.1:9001/browser
StorageFactory.Modules.UseAwsStorage();
return StorageFactory.Blobs.FromConnectionString(configuration.GetConnectionString("MinIOS3ConnectionString"));
var minIOConnectionString = configuration.GetConnectionString("MinIOS3ConnectionString")!;
return StorageFactory.Blobs.MinIO(GetValue(minIOConnectionString, "AccessKey"), GetValue(minIOConnectionString, "SecretKey"), "attachments", "us-east-1" /*Region doesn't matter for MinIO*/, GetValue(minIOConnectionString, "Endpoint"));
//#else
// Note that FluentStorage.AWS can be used with any S3 compatible S3 implementation such as Digital Ocean's Spaces Object Storage.
throw new NotImplementedException("Install and configure any storage supported by fluent storage (https://github.com/robinrodricks/FluentStorage/wiki/Blob-Storage)");
//#endif
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//#if (filesStorage == "AzureBlobStorage")
"AzureBlobStorageConnectionString": "UseDevelopmentStorage=true",
//#elif (filesStorage == "S3")
"MinIOS3ConnectionString": "minio.s3://keyId=minioadmin;key=minioadmin;serviceUrl=http://localhost:9000;bucket=attachments",
"MinIOS3ConnectionString": "Endpoint=http://localhost:9000;AccessKey=minioadmin;SecretKey=minioadmin",
//#endif
"ConnectionStrings_Comment": "The ConnectionStrings section contains database connection strings used by the application."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Condition=" '$(database)' == 'SqlServer' OR '$(database)' == ''" Include="Aspire.Hosting.SqlServer" />
<PackageReference Condition=" '$(database)' == 'PostgreSQL' OR '$(database)' == '' " Include="Aspire.Hosting.PostgreSQL" />
<PackageReference Condition=" '$(filesStorage)' == 'AzureBlobStorage' OR '$(filesStorage)' == '' " Include="Aspire.Hosting.Azure.Storage" />
<PackageReference Condition=" '$(filesStorage)' == 'S3' OR '$(filesStorage)' == '' " Include="CommunityToolkit.Aspire.Hosting.Minio" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,14 @@
{
azurite
.WithLifetime(ContainerLifetime.Persistent)
.WithDataVolume("BoilerplateStorage")
.WithBlobPort(10000)
.WithQueuePort(10001)
.WithTablePort(10002);
.WithDataVolume("BoilerplateStorage");
})
.AddBlobs("blobs");

//#elif (filesStorage == "S3")
// minio docker instance for testing purposes.
var s3Storage = builder.AddContainer("minio", "minio/minio", "latest")
.WithLifetime(ContainerLifetime.Persistent)
.WithArgs("server", "/data", "--console-address", ":9001") // Add MinIO server command
.WithEnvironment("MINIO_ROOT_USER", "minioadmin")
.WithEnvironment("MINIO_ROOT_PASSWORD", "minioadmin")
.WithEndpoint(port: 9000, targetPort: 9000, "api")
.WithEndpoint(port: 9001, targetPort: 9001, "console") // http://127.0.0.1:9001/browser
.WithVolume("/var/lib/minio/Boilerplate/data");
var username = builder.AddParameter("user", "minioadmin");
var password = builder.AddParameter("password", "minioadmin", secret: true);
var s3Storage = builder.AddMinioContainer("minio", rootUser: username, rootPassword: password);
//#endif

var serverWebProject = builder.AddProject<Boilerplate_Server_Web>("serverweb") // Replace . with _ if needed to ensure the project builds successfully.
Expand All @@ -70,9 +61,7 @@
//#if (filesStorage == "AzureBlobStorage")
serverApiProject.WithReference(azureBlobStorage, "AzureBlobStorageConnectionString").WaitFor(azureBlobStorage);
//#elif (filesStorage == "S3")
serverApiProject
.WithEnvironment("ConnectionStrings__MinIOS3ConnectionString", "minio.s3://keyId=minioadmin;key=minioadmin;serviceUrl=http://localhost:9000;bucket=attachments")
.WaitFor(s3Storage);
serverApiProject.WithReference(s3Storage, "MinIOS3ConnectionString").WaitFor(s3Storage);
//#endif

//#else
Expand All @@ -87,9 +76,7 @@
//#if (filesStorage == "AzureBlobStorage")
serverWebProject.WithReference(azureBlobStorage, "AzureBlobStorageConnectionString").WaitFor(azureBlobStorage);
//#elif (filesStorage == "S3")
serverWebProject
.WithEnvironment("ConnectionStrings__MinIOS3ConnectionString", "minio.s3://keyId=minioadmin;key=minioadmin;serviceUrl=http://localhost:9000;bucket=attachments")
.WaitFor(s3Storage);
serverWebProject.WithReference(s3Storage, "MinIOS3ConnectionString").WaitFor(s3Storage);
//#endif

//#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static WebApplication UseSiteMap(this WebApplication app)
//#endif
</sitemapindex>";

var baseUrl = context.Request.GetWebAppUrl();
var baseUrl = context.Request.GetBaseUrl();

context.Response.Headers.ContentType = "application/xml";

Expand All @@ -54,7 +54,7 @@ public static WebApplication UseSiteMap(this WebApplication app)
? urls.Union(CultureInfoManager.SupportedCultures.SelectMany(sc => urls.Select(url => $"{sc.Culture.Name}{url}"))).ToArray()
: urls;

var baseUrl = context.Request.GetWebAppUrl();
var baseUrl = context.Request.GetBaseUrl();

var siteMap = @$"{siteMapHeader}
{string.Join(Environment.NewLine, urls.Select(u => $"<url><loc>{new Uri(baseUrl, u)}</loc></url>"))}
Expand All @@ -68,7 +68,7 @@ public static WebApplication UseSiteMap(this WebApplication app)
//#if(module == "Sales")
app.MapGet("/products.xml", [AppResponseCache(SharedMaxAge = 60 * 5)] async (IProductViewController controller, HttpContext context) =>
{
var baseUrl = context.Request.GetWebAppUrl();
var baseUrl = context.Request.GetBaseUrl();
var products = await controller.WithQuery(new ODataQuery() { Select = $"{nameof(ProductDto.ShortId)},{nameof(ProductDto.Name)}" }).Get(context.RequestAborted);
var productsUrls = products.Select(p => p.PageUrl).ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"PostgreSQLConnectionString": "User ID=postgres;Password=postgres;Host=localhost;Database=BoilerplateDb;",
"MySqlConnectionString": "Server=localhost;Port=3306;Database=BoilerplateDb;Uid=root;Pwd=123456;",
"AzureBlobStorageConnectionString": "UseDevelopmentStorage=true",
"MinIOS3ConnectionString": "minio.s3://keyId=minioadmin;key=minioadmin;serviceUrl=http://localhost:9000;bucket=attachments"
"MinIOS3ConnectionString": "Endpoint=http://localhost:9000;AccessKey=minioadmin;SecretKey=minioadmin"
},
"Identity": {
"JwtIssuerSigningKeySecret": "VeryLongJWTIssuerSiginingKeySecretThatIsMoreThan64BytesToEnsureCompatibilityWithHS512Algorithm",
Expand Down
Loading