Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
still unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherPotato committed Jan 7, 2023
1 parent 71db92b commit 64778ed
Show file tree
Hide file tree
Showing 28 changed files with 948 additions and 760 deletions.
Binary file added .github/Icon.ico
Binary file not shown.
Binary file added .github/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Agirax Hosting Server

> At the moment, Agirax is designed to run only on Windows systems. We plan to port it to more platforms later.
Agiras is an HTTP server that uses Sisk to host static files, Sisk modules and PHP applications. At the moment its development is still in the alpha phase, and therefore, **it should not be used for production**.

Known issues:
Expand Down
2 changes: 2 additions & 0 deletions modules/compress-images/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
11 changes: 11 additions & 0 deletions modules/compress-images/compress-images.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>compress_images</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
2 changes: 2 additions & 0 deletions modules/less-compiler/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
11 changes: 11 additions & 0 deletions modules/less-compiler/less-compiler.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>less_compiler</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
21 changes: 21 additions & 0 deletions modules/minify/Factory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Sisk.Core.Routing.Handlers;
using System.Collections.Specialized;

namespace minify
{
internal class Factory : RequestHandlerFactory
{
public override IRequestHandler[] BuildRequestHandlers()
{
return new[]
{
new MinifyHtmlCssJsRequestHandler()
};
}

public override void Setup(NameValueCollection setupParameters)
{
;
}
}
}
78 changes: 78 additions & 0 deletions modules/minify/RequestHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Sisk.Core.Http;
using Sisk.Core.Routing.Handlers;
using System.Text.RegularExpressions;

namespace minify
{
public class MinifyHtmlCssJsRequestHandler : IRequestHandler
{
public string Identifier { get; init; } = Guid.NewGuid().ToString();
public RequestHandlerExecutionMode ExecutionMode { get; init; } = RequestHandlerExecutionMode.AfterResponse;

public HttpResponse? Execute(HttpRequest request, HttpContext context)
{
var rgxOptions = RegexOptions.Compiled | RegexOptions.Multiline;

if (context.RouterResponse == null)
return null;
if (context.RouterResponse.Content == null)
return null;

string? mediaType = context.RouterResponse.Headers["Content-Type"] ?? context.RouterResponse.Content.Headers.ContentType?.MediaType;
string content = context.RouterResponse.Content.ReadAsStringAsync().Result;

if (mediaType == null)
return null;

else if (mediaType.StartsWith("text/html"))
{
string minified = content;

// comments and line start
minified = Regex.Replace(minified, @"<!--(.*?)-->|\s\B", "", rgxOptions);

// spaced tags
minified = Regex.Replace(minified, @">[\r\n\s]+<", "><", rgxOptions);

context.RouterResponse.Content = new StringContent(minified);
context.RouterResponse.Headers.Set("Content-Type", mediaType);
context.RouterResponse.Headers.Set("X-Minified-By", "Agirax");
return context.RouterResponse;
}
else if (mediaType.StartsWith("application/javascript"))
{
string minified = content;

// start space
minified = Regex.Replace(minified, @"^\s+", "", rgxOptions);
// single line comments
minified = Regex.Replace(minified, @"^[^\n][\t\s]+//.*\n", "><", rgxOptions);
// multiline line comments
minified = Regex.Replace(minified, @"\/\*[\s\S]*?\*\/", "><", rgxOptions);

context.RouterResponse.Content = new StringContent(minified);
context.RouterResponse.Headers.Set("Content-Type", mediaType);
context.RouterResponse.Headers.Set("X-Minified-By", "Agirax");
return context.RouterResponse;
}
else if (mediaType.StartsWith("text/css"))
{
string minified = content;

// multiline line comments
minified = Regex.Replace(minified, @"\/\*[\s\S]*?\*\/", "><", rgxOptions);
// trim all spaces
minified = Regex.Replace(minified, @"^\s+|[\r\n\t]+", "", rgxOptions);

context.RouterResponse.Content = new StringContent(minified);
context.RouterResponse.Headers.Set("Content-Type", mediaType);
context.RouterResponse.Headers.Set("X-Minified-By", "Agirax");
return context.RouterResponse;
}
else
{
return null;
}
}
}
}
14 changes: 14 additions & 0 deletions modules/minify/minify.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\core\src\Sisk.Core.csproj" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions modules/resize-images/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
11 changes: 11 additions & 0 deletions modules/resize-images/resize-images.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>resize_images</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
145 changes: 0 additions & 145 deletions src/ChildProcessTracker.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/Cli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ internal static class Cli
{
private static void LogMessage(string level, string message)
{
Console.WriteLine($"{"[" + level + "]",-7} {message}");
string prefix = $"{DateTime.Now:R}{level,6} : ";
Console.Write(prefix + string.Join("\n" + prefix, message.Split("\n")) + "\n");
}

internal static void Log(string message)
Expand All @@ -14,6 +15,7 @@ internal static void Log(string message)

internal static void Warn(string message)
{
Program.startedWithWarnings = true;
LogMessage("warn", message);
}

Expand Down
Loading

0 comments on commit 64778ed

Please sign in to comment.