router fix
This commit is contained in:
parent
bac1c8368f
commit
f66c0ea706
@ -73,9 +73,8 @@ internal static class Program
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger.LogInfo(logContext, $"{ctx.Request.HttpMethod} request for {ctx.Request.RawUrl} from {ctx.Request.RemoteEndPoint}");
|
logger.LogInfo(logContext, $"{ctx.Request.HttpMethod} request for {ctx.Request.RawUrl} from {ctx.Request.RemoteEndPoint}");
|
||||||
if(router.TryResolve(ctx))
|
bool isRequestHandled = router.TryResolve(ctx);
|
||||||
logger.LogInfo(logContext, "request handled");
|
logger.LogInfo(logContext, isRequestHandled ? "request handled" : "request rejected");
|
||||||
else logger.LogInfo(logContext, "request rejected");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -27,7 +27,9 @@ public class Router
|
|||||||
else if(ctx.Request.HttpMethod == "GET")
|
else if(ctx.Request.HttpMethod == "GET")
|
||||||
{
|
{
|
||||||
string urlPath = ctx.Request.Url.AbsolutePath;
|
string urlPath = ctx.Request.Url.AbsolutePath;
|
||||||
var ext = Path.Extension(urlPath).Str;
|
string ext = urlPath.EndsWith(".js.map")
|
||||||
|
? ".js.map" // extname of '*.js.map' is '.map' so it has to be set explicitely
|
||||||
|
: Path.Extension(urlPath).Str;
|
||||||
IOPath filePath;
|
IOPath filePath;
|
||||||
switch (ext)
|
switch (ext)
|
||||||
{
|
{
|
||||||
@ -40,13 +42,13 @@ public class Router
|
|||||||
ctx.Response.Headers.Set("Content-Type", "text/css");
|
ctx.Response.Headers.Set("Content-Type", "text/css");
|
||||||
break;
|
break;
|
||||||
case "js":
|
case "js":
|
||||||
filePath = Path.Concat(publicDirPath, "js", urlPath);
|
case "js.map":
|
||||||
|
case "jsx":
|
||||||
|
case "ts":
|
||||||
|
case "tsx":
|
||||||
|
filePath = Path.Concat(publicDirPath, "scripts", urlPath);
|
||||||
ctx.Response.Headers.Set("Content-Type", "text/javascript");
|
ctx.Response.Headers.Set("Content-Type", "text/javascript");
|
||||||
break;
|
break;
|
||||||
case "map":
|
|
||||||
if (urlPath.EndsWith(".js.map"))
|
|
||||||
goto case "js";
|
|
||||||
goto default;
|
|
||||||
default:
|
default:
|
||||||
if (urlPath == "/")
|
if (urlPath == "/")
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user