Add debug web server
This commit is contained in:
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
|
||||
|
||||
@@ -125,3 +125,13 @@ function StringLastIndexOf(str as string, substr as string) as integer
|
||||
end while
|
||||
return index
|
||||
end function
|
||||
|
||||
function PathJoin(path1 as string, path2 as string) as string
|
||||
if path1.EndsWith("/")
|
||||
path1 = path1.left(path1.len() - 1)
|
||||
end if
|
||||
if path2.StartsWith("/")
|
||||
path2 = path2.Mid(1)
|
||||
end if
|
||||
return path1 + "/" + path2
|
||||
end function
|
||||
@@ -138,5 +138,5 @@ namespace WebUtils
|
||||
end for
|
||||
return url
|
||||
end function
|
||||
|
||||
|
||||
end namespace
|
||||
Reference in new issue
Block a user