Skip to content

Commit 4f57a78

Browse files
committed
fixed #6, status codes can now be accessed everywhere
1 parent d72abbd commit 4f57a78

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

LinkRouter/App/Configuration/Config.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,10 @@ public void CompileRoutes()
5454
var replacements = new List<(int Index, int Length, string NewText)>();
5555

5656
var escaped = Regex.Escape(route.Route);
57-
58-
Console.WriteLine(escaped);
5957

60-
var pattern = new Regex(@"\\\{(\d|\w+)\}");
58+
var pattern = new Regex(@"\\\{(\d|\w+)\}", RegexOptions.CultureInvariant);
6159

6260
var matches = pattern.Matches(escaped);
63-
64-
Console.WriteLine(matches.Count + " matches found.");
6561

6662
foreach (var match in matches.Select(x => x))
6763
{
@@ -86,8 +82,6 @@ public void CompileRoutes()
8682
compiled.CompiledPattern = new Regex(compiledRouteBuilder.ToString(),
8783
RegexOptions.Compiled | RegexOptions.CultureInvariant);
8884

89-
Console.WriteLine(compiled.CompiledPattern.ToString());
90-
9185
var duplicate = matches
9286
.Select((m, i) => m.Groups[1].Value)
9387
.GroupBy(x => x)

LinkRouter/App/Http/Controllers/RedirectController.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,13 @@ public async Task<ActionResult> RedirectToExternalUrl(string path)
5454
.Inc();
5555

5656
if (Config.NotFoundBehavior.RedirectOn404)
57-
return Redirect(Config.NotFoundBehavior.RedirectUrl);
57+
if (Config.ErrorCodePattern.IsMatch(Config.NotFoundBehavior.RedirectUrl))
58+
{
59+
var errorCodeMatch = Config.ErrorCodePattern.Match(Config.NotFoundBehavior.RedirectUrl);
60+
var errorCode = int.Parse(errorCodeMatch.Groups[1].Value);
61+
return StatusCode(errorCode);
62+
} else
63+
return Redirect(Config.NotFoundBehavior.RedirectUrl);
5864

5965
return NotFound();
6066
}
@@ -87,6 +93,13 @@ public IActionResult GetRootRoute()
8793
.Inc();
8894

8995
string url = Config.RootRoute;
96+
97+
if (Config.ErrorCodePattern.IsMatch(url))
98+
{
99+
var errorCodeMatch = Config.ErrorCodePattern.Match(url);
100+
var errorCode = int.Parse(errorCodeMatch.Groups[1].Value);
101+
return StatusCode(errorCode);
102+
}
90103

91104
return Redirect(url);
92105
}

0 commit comments

Comments
 (0)