-
Notifications
You must be signed in to change notification settings - Fork 147
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
Open
Odonno
wants to merge
14
commits into
CommunityToolkit:main
Choose a base branch
from
Odonno:feat/umami
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e541ea8
feat: create Umami hosting project
Odonno 9e2d7c9
docs: add umami example project
Odonno c1665d4
docs: add umami hosting integration to the readme
Odonno 0507eb8
docs: update C# example in the `AddUmami` xml docs
Odonno 913a7b6
docs: add readme for the hosting umami nuget package
Odonno cfe119d
test: add tests for Umami hosting integration
Odonno d695cb3
refactor: replace blazor app with vite app in Umami example project
Odonno 59527c6
docs: dynamically create website & generate umami tracking script
Odonno bbea835
fix: manually construct connection string to access db from umami
Odonno 221f0ed
refactor: rename extension method to `WithPostgreSQL`
Odonno b4892a4
fix: fix slnx after rebase
Odonno fb7df93
Merge branch 'main' into feat/umami
aaronpowell 6fddb26
Merge branch 'main' into feat/umami
aaronpowell 00dbb18
Update examples/umami/CommunityToolkit.Aspire.Hosting.Umami.AppHost/C…
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
73 changes: 73 additions & 0 deletions
73
examples/umami/CommunityToolkit.Aspire.Hosting.Umami.AppHost/AppHost.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); |
20 changes: 20 additions & 0 deletions
20
...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,20 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <Sdk Name="Aspire.AppHost.Sdk" Version="$(AspireAppHostSdkVersion)"/> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Aspire.Hosting.AppHost" /> | ||
| <PackageReference Include="Aspire.Hosting.NodeJS" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\src\CommunityToolkit.Aspire.Hosting.Umami\CommunityToolkit.Aspire.Hosting.Umami.csproj" IsAspireProjectResource="false" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
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.
Uh oh!
There was an error while loading. Please reload this page.