Repository navigation
Add Umami hosting integration #956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8e94459
feat: create Umami hosting project
Odonno eaf2934
docs: add umami example project
Odonno ba37a16
docs: add umami hosting integration to the readme
Odonno 93eeedc
docs: update C# example in the `AddUmami` xml docs
Odonno 9b4ccb4
docs: add readme for the hosting umami nuget package
Odonno d920bae
test: add tests for Umami hosting integration
Odonno f8cb4dc
refactor: replace blazor app with vite app in Umami example project
Odonno f75052d
docs: dynamically create website & generate umami tracking script
Odonno 2385477
fix: manually construct connection string to access db from umami
Odonno 00b6a1d
refactor: rename extension method to `WithPostgreSQL`
Odonno a13e165
fix: fix slnx after rebase
Odonno 31180b5
Merge branch 'main' into feat/umami
aaronpowell fdbf0ab
Merge branch 'main' into feat/umami
aaronpowell e9053e6
Update examples/umami/CommunityToolkit.Aspire.Hosting.Umami.AppHost/C…
aaronpowell adc1ff0
ci: fix package resolution
Odonno e75580d
Merge branch 'main' into feat/umami
aaronpowell cbf3876
Merge branch 'main' into feat/umami
aaronpowell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...Toolkit.Aspire.Hosting.Umami.AppHost/CommunityToolkit.Aspire.Hosting.Umami.AppHost.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Aspire.AppHost.Sdk/13.1.0"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.JavaScript" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Umami\CommunityToolkit.Aspire.Hosting.Umami.csproj" IsAspireProjectResource="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
73 changes: 73 additions & 0 deletions
73
examples/umami/CommunityToolkit.Aspire.Hosting.Umami.AppHost/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| using System.Net.Http.Headers; | ||
| using System.Net.Http.Json; | ||
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| const string websiteId = "204ea2a3-d77d-400e-9e6d-0db81de293f3"; | ||
|
|
||
| var password = builder.AddParameter("db-password", "12345678"); | ||
|
|
||
| var postgres = builder | ||
| .AddPostgres("postgres", password: password, port: 61118) | ||
| .WithLifetime(ContainerLifetime.Persistent); | ||
| var postgresdb = postgres.AddDatabase("postgresdb"); | ||
|
|
||
| var umami = builder | ||
| .AddUmami("umami", port: 55932) | ||
| .WithPostgreSQL(postgresdb) | ||
| .OnResourceReady(async (resource, _, ct) => | ||
| { | ||
| var umamiEndpoint = await resource.GetEndpoint("http").GetValueAsync(ct).ConfigureAwait(false); | ||
|
|
||
| using var umamiApiHttpClient = new HttpClient(); | ||
| umamiApiHttpClient.BaseAddress = new Uri(umamiEndpoint!); | ||
|
|
||
| const string defaultUmamiUser = "admin"; | ||
| const string defaultUmamiPassword = "umami"; | ||
|
|
||
| var loginResponseMessage = await umamiApiHttpClient.PostAsJsonAsync( | ||
| "/api/auth/login", | ||
| new UmamiAuthLoginPayload(defaultUmamiUser, defaultUmamiPassword), | ||
| ct | ||
| ); | ||
|
|
||
| loginResponseMessage.EnsureSuccessStatusCode(); | ||
| var loginResponse = await loginResponseMessage.Content.ReadFromJsonAsync<UmamiAuthLoginResponse>(ct); | ||
| var token = loginResponse?.Token; | ||
| if (token is null) | ||
| { | ||
| throw new Exception("Token not found"); | ||
| } | ||
|
|
||
| umamiApiHttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); | ||
|
|
||
| var existingWebsite = await umamiApiHttpClient.GetFromJsonAsync<UmamiGetWebsiteResponse>( | ||
| $"/api/websites/{websiteId}", | ||
| ct | ||
| ); | ||
| if (existingWebsite is not null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var createWebsiteResponseMessage = await umamiApiHttpClient.PostAsJsonAsync( | ||
| "/api/websites", | ||
| new UmamiCreateWebsitePayload(websiteId, "localhost", "localhost"), | ||
| ct | ||
| ); | ||
| createWebsiteResponseMessage.EnsureSuccessStatusCode(); | ||
| }); | ||
|
|
||
| var front = builder | ||
| .AddJavaScriptApp("front", "../umami-vite-app") | ||
| .WithEndpoint(name: "http", scheme: "http", env: "PORT") | ||
| .WaitFor(umami) | ||
| .WithEnvironment("VITE_UMAMI_ENDPOINT", umami.GetEndpoint("http")) | ||
| .WithEnvironment("VITE_UMAMI_WEBSITE_ID", websiteId); | ||
|
|
||
| builder.Build().Run(); | ||
|
|
||
| public record UmamiAuthLoginPayload(string Username, string Password); | ||
| public record UmamiAuthLoginResponse(string Token); | ||
| public record UmamiGetWebsiteResponse(string Id, string Name, string Domain); | ||
| public record UmamiCreateWebsitePayload(string Id, string Name, string Domain); | ||
29 changes: 29 additions & 0 deletions
29
examples/umami/CommunityToolkit.Aspire.Hosting.Umami.AppHost/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "https://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "https": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "https://localhost:17088;http://localhost:15104", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21297", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22074" | ||
| } | ||
| }, | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15104", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19272", | ||
| "ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20234" | ||
| } | ||
| } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
examples/umami/CommunityToolkit.Aspire.Hosting.Umami.AppHost/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| pnpm-debug.log* | ||
| lerna-debug.log* | ||
|
|
||
| node_modules | ||
| dist | ||
| dist-ssr | ||
| *.local | ||
|
|
||
| # Editor directories and files | ||
| .vscode/* | ||
| !.vscode/extensions.json | ||
| .idea | ||
| .DS_Store | ||
| *.suo | ||
| *.ntvs* | ||
| *.njsproj | ||
| *.sln | ||
| *.sw? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <!doctype html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8" /> | ||
| <link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| <title>umami-vite-app</title> | ||
| </head> | ||
| <body> | ||
| <div id="app"></div> | ||
| <script type="module" src="/src/main.ts"></script> | ||
| </body> | ||
| </html> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that this is only for something you want in this demo app and not something you'd need to do all the time right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is for demo purpose.