NetCoreServer
NetCoreServer copied to clipboard
Simple file server?
How would I use NetCoreServer to serve a "directory browser"/file server like https://ostechnix.com/how-to-setup-a-file-server-in-minutes-using-python/?
Another example: https://github.com/natemcmaster/dotnet-serve
dotnet tool install --global dotnet-serve
dotnet serve -p 8000
I know this is a late reply, but in case you still need help...
string wroot = @"www";
// Process HTTP request methods
if (request.Method == "HEAD")
{
UIupdate.UpdateNetworkOutput("https", "Request HEAD", Color.LimeGreen);
SendResponseAsync(Response.MakeHeadResponse());
}
else if (request.Method == "GET")
{
string path = wroot + request.Url.Replace("/", @"\");
UIupdate.UpdateNetworkOutput("https", $"Request Path: {path}", Color.LimeGreen);
// Begin https://github.com/chronoxor Contribution
string content;
try { content = File.ReadAllText(path); }
catch { content = "Invalid Request\n\nAre you lost?"; }
Response.Clear();
Response.SetBegin(200);
Response.SetContentType(Path.GetExtension(path));
Response.SetHeader("Cache-Control", $"max-age=3600");
Response.SetBody(content);
SendResponseAsync(Response);
// End https://github.com/chronoxor Contribution
}
Something like this above will serve files using either the HttpServer example or the HttpsServer example.
I hope this helps.
@thewhiterabbit Thanks. Looking at that, it looks like it only works for files, not folders - is that correct?
Currently it would only see a file and return the text.
You can add in some statement to check for folders and return default files within them based on regex or string comparison.