Skip to content

Commit

Permalink
Merge pull request #233 from FBoucher/vnext
Browse files Browse the repository at this point in the history
Fixing the mapping of the custom domain
  • Loading branch information
FBoucher authored Dec 6, 2020
2 parents 23fc8f4 + 200d734 commit ec9dafb
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
17 changes: 17 additions & 0 deletions post-deployment-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

Of course the beauty of a URL shortener is to have short link and this is done the best by a naked domain (domain.com). To realized this you would need to by an expensive certificate with a wild card, and this doesn't fit in the goals of this project. We will achieve it nervertheless by having a secure www.domain.com and doing a dynamic forward of domain.com to www.domain.com.

[<img src="https://img.youtube.com/vi/srZv8aj3ZP8/maxresdefault.jpg" width="50%">](https://youtu.be/srZv8aj3ZP8)

[https://youtu.be/srZv8aj3ZP8](https://youtu.be/srZv8aj3ZP8)
### 1- Assign a Domain to the Azure Function

Let`s start by Adding a domain to the App Service.
Expand Down Expand Up @@ -92,8 +95,22 @@ The URL shortener is now completly configured, and your users will be pleased. T

The TinyBlazorAdmin is the place to manage all your URLs. Create a new Page rule to redirect all call to your domain and the prefix of your choice. ( ex: admin.07f.ca, manager.07f.ca, new.07f.ca, etc)




### 5- Add the new Custom Domain to the Settings file

The last step is to update the `src\shortenerTools\settings.json`. This is the setting file for the Azure Function. Add (or edit if already present) `customDomain` and set it to your new domain.

```
"customDomain":"https://c5m.ca"
```


Congradulation, you are all set!



---


Expand Down
10 changes: 5 additions & 5 deletions src/adminTools/adminBlazorWebsite/src/adminBlazorWebsite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.9" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" />
</ItemGroup>

Expand Down
7 changes: 3 additions & 4 deletions src/shortenerTools/UrlList/UrlList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ public static async Task<IActionResult> Run(
}
else
{
userId = principal.FindFirst(ClaimTypes.GivenName).Value;
log.LogInformation("Authenticated user {user}.", userId);
userId = principal.FindFirst(ClaimTypes.GivenName).Value;
log.LogInformation("Authenticated user {user}.", userId);
}

result.UrlList = await stgHelper.GetAllShortUrlEntities();
result.UrlList = result.UrlList.Where(p => !(p.IsArchived ?? false)).ToList();
//var host = req.HttpContext.RequestUri.GetLeftPart(UriPartial.Authority);
var host = req.Host.Host;
var host = string.IsNullOrEmpty(config["customDomain"]) ? req.Host.Host: config["customDomain"].ToString();
foreach (ShortUrlEntity url in result.UrlList)
{
url.ShortUrl = Utility.GetShortUrl(host, url.RowKey);
Expand Down
4 changes: 1 addition & 3 deletions src/shortenerTools/UrlShortener/UrlShortener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ public static async Task<IActionResult> Run(

await stgHelper.SaveShortUrlEntity(newRow);

//var host = req.RequestUri.GetLeftPart(UriPartial.Authority);
var host = req.Host.Host;
log.LogInformation($"-> host = {host}");
var host = string.IsNullOrEmpty(config["customDomain"]) ? req.Host.Host: config["customDomain"].ToString();
result = new ShortResponse(host, newRow.Url, newRow.RowKey, newRow.Title);

log.LogInformation("Short Url created.");
Expand Down
3 changes: 1 addition & 2 deletions src/shortenerTools/UrlUpdate/UrlUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public static async Task<IActionResult> Run(
StorageTableHelper stgHelper = new StorageTableHelper(config["UlsDataStorage"]);

result = await stgHelper.UpdateShortUrlEntity(input);
//var host = req.RequestUri.GetLeftPart(UriPartial.Authority);
var host = req.Host.Host;
var host = string.IsNullOrEmpty(config["customDomain"]) ? req.Host.Host: config["customDomain"].ToString();
result.ShortUrl = Utility.GetShortUrl(host, result.RowKey);

}
Expand Down
4 changes: 2 additions & 2 deletions src/shortenerTools/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"FUNCTIONS_V2_COMPATIBILITY_MODE":"true",
"UlsDataStorage":"",
"defaultRedirectUrl":"https://azure.com"

"defaultRedirectUrl":"https://azure.com",
"customDomain":"https://c5m.ca"
}
}
4 changes: 2 additions & 2 deletions src/shortenerTools/shortenerTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.8" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.0.2" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand Down

0 comments on commit ec9dafb

Please sign in to comment.