Add debug web server

This commit is contained in:
Brahim Hadriche committed 2022-11-29 23:13:52 -05:00
1 parent 68a32afc38
commit a059702a0e
6 files changed
+50 -13

No files matched your search

@@ -35,7 +35,7 @@ namespace Http
response.Default(204, "OK")
end if
return true
end function)
end function)
end function
end class
@@ -71,8 +71,8 @@ namespace Http
sets = period.GetChildNodes()
for each set in sets
attributes = set.GetAttributes()
contentType = attributes.contentType
mimeType = attributes.mimeType
contentType = attributes.contentType
mimeType = attributes.mimeType
' If the DASH already has thumbnails, abort
if contentType = "image" or (mimeType <> invalid and mimeType.StartsWith("image"))
return ""
@@ -4,22 +4,34 @@ namespace Http
private log as log.Logger
private root
private filesOnly
private route
private showDirectories
private showHidden
function new(root as string, filesOnly = false as boolean)
function new(route as string, root as string, showDirectories = false as boolean, showHidden = false as boolean)
super()
m.log = new log.Logger("HttpStaticFilesRouter")
m.root = root
m.filesOnly = filesOnly
m.route = route
m.showDirectories = showDirectories
m.showHidden = showHidden
m.Get("*", function(context as object) as boolean
router = context.router
request = context.request
response = context.response
decoded_path = WebUtils.UrlUnescape(request.route)
path = CreateObject("roPath", router.root + decoded_path)
if not request.route.StartsWith(router.route)
return false
end if
path_in_route = request.route.Mid(router.route.Len())
decoded_path = WebUtils.UrlUnescape(path_in_route)
full_path = PathJoin(router.root, decoded_path)
path = CreateObject("roPath", full_path)
fs = CreateObject("roFilesystem")
if not path.isValid()
@@ -37,9 +49,9 @@ namespace Http
end if
if stat.type = "directory"
if router.filesOnly
if not router.showDirectories
response.Default(403, "Forbidden")
return false
return true
end if
response.ContentType("text/html")
router.GenerateDirectoryListing(path, router, request, response)
@@ -141,8 +153,19 @@ namespace Http
if uriDir.len() > 0 and uriDir.right(1) <> "/"
uriDir = uriDir + "/"
end if
routeDir = router.route
if routeDir.len() > 0 and routeDir.right(1) <> "/"
routeDir = routeDir + "/"
end if
if not uriDir = routeDir
uri = uriDir + ".."
listing = listing + "<a href=" + Quote() + uri + Quote() + ">" + ".." + "</a>" + UnixNL()
end if
for each item in dirList
if item.left(1) <> "."
if router.showHidden or item.left(1) <> "."
indicator = invalid
stat = fs.stat(dir + item)
if stat <> invalid
@@ -11,6 +11,7 @@ import "pkg:/components/WebServer/Middleware/BasicAuthMiddleware.bs"
import "pkg:/components/WebServer/Middleware/DashRouter.bs"
#const WEB_SERVER_BASIC_AUTH = false
#const WEB_SERVER_PACKAGE_DEBUG = false
function Init()
m.top.functionName = "WebServerLoop"
@@ -38,7 +39,10 @@ function WebServerLoop()
m.server.UseRouter(new Http.CommandsApiRouter())
m.server.UseRouter(new Http.StateApiRouter())
m.server.UseRouter(new Http.InvidiousRouter())
m.server.UseRouter(new Http.HttpStaticFilesRouter(m.settings.WwwRoot))
m.server.UseRouter(new Http.HttpStaticFilesRouter("/", m.settings.WwwRoot))
#if WEB_SERVER_PACKAGE_DEBUG
m.server.UseRouter(new Http.HttpStaticFilesRouter("/debug", "pkg:/", true, true))
#end if
#if WEB_SERVER_BASIC_AUTH
m.server.UseRouter(new Http.BasicAuthMiddleware())
#end if