Skip to content
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

Allow redirection if non vanity provided #502

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -3,6 +3,7 @@ namespace Cloud5mins.ShortenerTools.Core.Domain
public class ShortenerSettings
{
public string DefaultRedirectUrl { get; set; }
public string RootRedirectUrl { get; set; }
public string CustomDomain { get; set; }
public string DataStorage { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Cloud5mins.ShortenerTools.Core.Domain;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Linq;
using System.Net;
using System.Security.Claims;
using System.Threading;
using System.Threading.Tasks;

namespace Cloud5mins.ShortenerTools.Functions
{
public class UrlRedirectRoot
{
private readonly ILogger _logger;
private readonly ShortenerSettings _settings;

public UrlRedirectRoot(ILoggerFactory loggerFactory, ShortenerSettings settings)
{
_logger = loggerFactory.CreateLogger<UrlRedirectRoot>();
_settings = settings;
}

[Function("UrlRedirectRoot")]
public async Task<HttpResponseData> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "/")]
HttpRequestData req,
ExecutionContext context)
{
string redirectUrl = _settings.RootRedirectUrl ?? _settings.DefaultRedirectUrl ?? "https://azure.com";
var res = req.CreateResponse(HttpStatusCode.Redirect);
res.Headers.Add("Location", redirectUrl);
return res;

}
}
}
15 changes: 15 additions & 0 deletions src/deployment/azureDeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
"description": "Default URL used when key passed by the user is not found."
}
},
"rootRedirectUrl": {
"defaultValue": "https://azure.com",
"type": "string",
"metadata": {
"description": "URL used someone access the root (/)."
}
},
"GitHubURL": {
"type": "string",
"defaultValue": "https://github.com/microsoft/AzUrlShortener.git",
Expand Down Expand Up @@ -117,6 +124,14 @@
{
"name": "defaultRedirectUrl",
"value": "[parameters('defaultRedirectUrl')]"
},
{
"name": "rootRedirectUrl",
"value": "[parameters('rootRedirectUrl')]"
},
{
"name": "AzureWebJobsDisableHomepage",
"value": "true"
}
]
},
Expand Down