-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd7a7f4
commit 5a326dc
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E37128E4-D0BF-4EC1-9F94-A0DD998E11AD}" | ||
EndProject | ||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Sergio", "src\Sergio\Sergio.fsproj", "{2DD9EFA4-5242-4F58-83F8-735A552FB30E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Debug|x64.Build.0 = Debug|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Debug|x86.Build.0 = Debug|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Release|x64.ActiveCfg = Release|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Release|x64.Build.0 = Release|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Release|x86.ActiveCfg = Release|Any CPU | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{2DD9EFA4-5242-4F58-83F8-735A552FB30E} = {E37128E4-D0BF-4EC1-9F94-A0DD998E11AD} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
open System.IO | ||
open Argu | ||
open Microsoft.AspNetCore.Builder | ||
open Microsoft.AspNetCore.Hosting | ||
open Microsoft.Extensions.Logging | ||
open System | ||
|
||
type CliArguments = | ||
| [<MainCommand; ExactlyOnce; First>] Root of path:string | ||
| Listener of string * int | ||
| Log_Level of int | ||
| GZip of bool | ||
with | ||
interface IArgParserTemplate with | ||
member s.Usage = | ||
match s with | ||
| Root _ -> "specify a working directory" | ||
| Listener _ -> "specify a listener (ex: --listener localhost 5001)" | ||
| Log_Level _ -> "set the log level (default = LogLevel.Error)" | ||
| GZip _ -> "enable gzip compress (default = False)" | ||
|
||
[<EntryPoint>] | ||
let main argv = | ||
let errorHandler = ProcessExiter(colorizer = function ErrorCode.HelpText -> None | _ -> Some ConsoleColor.Red) | ||
let parser = ArgumentParser.Create<CliArguments>(programName = "Sergio", errorHandler = errorHandler) | ||
|
||
match argv with | ||
| [||] -> parser.PrintUsage() |> printfn "%s" | ||
| _ -> | ||
let results = parser.ParseCommandLine argv | ||
|
||
let root = results.GetResult (Root, defaultValue = "/") | ||
let webRoot = | ||
match root |> Path.IsPathRooted with | ||
| true -> root | ||
| false -> Path.Combine [| Directory.GetCurrentDirectory(); root |] | ||
|
||
let listener = results.GetResult (Listener, defaultValue = ("localhost", 8080)) | ||
let url = listener |> fun (l, p) -> sprintf "https://%s:%i" l p | ||
|
||
let logLevel = results.GetResult (Log_Level, defaultValue = 4) | ||
let configureLog = | ||
fun (log : ILoggingBuilder) -> | ||
log.AddFilter(fun l -> l >= (LogLevel.ToObject(typedefof<LogLevel>, logLevel) :?> LogLevel)) | ||
.AddConsole() |> ignore | ||
|
||
let gzip = results.GetResult (GZip, defaultValue = false) | ||
|
||
WebHostBuilder() | ||
.ConfigureLogging(configureLog) | ||
.UseKestrel() | ||
.UseContentRoot(webRoot) | ||
.UseWebRoot(webRoot) | ||
.UseUrls(url) | ||
.ConfigureServices(fun services -> | ||
if gzip then services.AddResponseCompression(fun compression -> compression.EnableForHttps <- true) |> ignore) | ||
.Configure(fun app -> | ||
if gzip then app.UseResponseCompression() |> ignore | ||
|
||
app.UseDefaultFiles() | ||
.UseStaticFiles() | ||
|> ignore) | ||
.Build() | ||
.Run() | ||
|
||
0 // return an integer exit code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Argu" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" /> | ||
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0-preview.3.20215.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |