Test Project Created
+ Implemented Request Processing (Cache => Regex Events => Razor Pages => Static Content) + Rendering based on domain works - Areas are not implemented + Content Type Map now defines `.cshtml` files and default mime type was changed to "text/plain" + GetStaticFile no longer returns private templates/layouts (used to be able to view those in plain text by requesting with a fully qualified path) I will make more concise tests in a bit (I was not pushing to git properly, so have to make big commits for the time being)
This commit is contained in:
@@ -1,9 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using WebServer;
|
||||
|
||||
namespace WebServer.Test {
|
||||
internal class Program {
|
||||
internal static void Main(string[] args) {
|
||||
Console.WriteLine("Hello, World!");
|
||||
var server = new HttpConfiguration() {
|
||||
DefaultDomain = "localhost",
|
||||
AutoStart = true,
|
||||
Port = 8080,
|
||||
DebugMode = true
|
||||
}.CreateServer(new HttpLogger());
|
||||
|
||||
_ = Console.ReadLine();
|
||||
}
|
||||
}
|
||||
public class HttpLogger : IHttpLogger {
|
||||
public void Log(string message) => Console.WriteLine(message);
|
||||
|
||||
public void LogError(HttpListenerContext context, List<MethodBase> methodsUsed, Exception exception)
|
||||
=> Console.WriteLine(exception);
|
||||
|
||||
public void LogRequest(HttpListenerContext context, HttpResponse response, List<MethodBase> methodsUsed)
|
||||
=> Console.WriteLine($"[{(int)response.StatusCode}] {context.Request.Url?.PathAndQuery}");
|
||||
}
|
||||
}
|
||||
31
WebServer.Test/Views/localhost/_Layout.cshtml
Normal file
31
WebServer.Test/Views/localhost/_Layout.cshtml
Normal file
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>@ViewBag.Title</title>
|
||||
<link href="https://kavemans.dev/src/styles/framework.css" type="text/css" rel="stylesheet" />
|
||||
<link href="https://kavemans.dev/src/styles/common.css" type="text/css" rel="stylesheet" />
|
||||
<link href="https://kavemans.dev/src/styles/main.css" type="text/css" rel="stylesheet" />
|
||||
@RenderSection("Styles", required: false)
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
body {
|
||||
background-image: url('https://kavemans.dev/src/images/Chalkboard.webp');
|
||||
background-size: cover;
|
||||
background-position: center center;
|
||||
}
|
||||
|
||||
.ice {
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="centerize stickyFooter">
|
||||
@RenderBody()
|
||||
</body>
|
||||
</html>
|
||||
16
WebServer.Test/Views/localhost/_StatusPage.cshtml
Normal file
16
WebServer.Test/Views/localhost/_StatusPage.cshtml
Normal file
@@ -0,0 +1,16 @@
|
||||
@using RazorLight
|
||||
@inherits TemplatePage<WebServer.Models.StatusPageModel>
|
||||
@model WebServer.Models.StatusPageModel
|
||||
@{
|
||||
Layout = @"_Layout.cshtml";
|
||||
ViewBag.Title = $"{Model.StatusCodeAsUShort} - {Model.Header}";
|
||||
}
|
||||
<div class="ice centerize">
|
||||
<div style="font-size: 2em;">@Model.Header</div>
|
||||
<span>@Model.Details</span>
|
||||
@if (Model.Exception != null) {
|
||||
<div style="padding: 5px; border-radius: 5px; background: rgba(0, 0, 0, 0.5); box-shadow: inset rgb(255 255 255 / 20%) 0 0 0 2px; width: auto; max-width: 95%; text-align: left;">
|
||||
<pre style="margin: 0;">@Model.Exception</pre>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
8
WebServer.Test/Views/localhost/test123/index.cshtml
Normal file
8
WebServer.Test/Views/localhost/test123/index.cshtml
Normal file
@@ -0,0 +1,8 @@
|
||||
@using RazorLight
|
||||
@inherits TemplatePage<object?>
|
||||
@{
|
||||
Layout = "/_Layout.cshtml";
|
||||
ViewBag.Title = "Hello World!";
|
||||
}
|
||||
|
||||
<u>Hello from test123</u>
|
||||
@@ -7,25 +7,23 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<PublishAot>true</PublishAot>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Not entirely sure what this does -->
|
||||
<!-- Remove all site contents and Razor pages from being compiled -->
|
||||
<None Remove="Views\**" />
|
||||
<!-- Remove all Razor pages from being compiled in project -->
|
||||
<Content Remove="Views/**.cshtml" />
|
||||
<!-- But, inlude in Editor/Solution Explorer -->
|
||||
<Compile Remove="Views\**" />
|
||||
<Content Include="Views\**" />
|
||||
<!-- Copy everything from views into output directory-->
|
||||
<None Include="Views/**">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<!-- Do not compile contents -->
|
||||
<Compile Remove="Views\**" />
|
||||
<!-- But, inlude in Editor -->
|
||||
<Content Include="Views\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Web Server assembly reference -->
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WebServer\SimpleWebServer.csproj" />
|
||||
<ProjectReference Include="..\WebServer\WebServer.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user