import "pkg:/components/Web/PlayletWebServer/Middleware/SearchHistoryRouter.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/StateApiRouter.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/PreferencesRouter.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/InvidiousRouter.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/PlayQueueRouter.bs" import "pkg:/components/Web/WebServer/Middleware/CorsMiddleware.bs" import "pkg:/components/Web/WebServer/Middleware/HttpStaticFilesRouter.bs" import "pkg:/components/Web/PlayletWebServer/Middleware/PlayletLibUrlsRouter.bs" function Init() m.top.packageName = "Playlet" m.top.serverName = "Playlet Web Server" end function function GetServerAddress(unused as dynamic) as dynamic port = m.top.port ip = m.top.applicationInfo@.GetLocalIpAddress() if StringUtils.IsNullOrEmpty(ip) return invalid end if return `http://${ip}:${port}` end function function SetupRoutes(server as object) homeRouter = new Http.HttpRouter() homeRouter.Get("/", function(context as object) as boolean response = context.response response.Redirect("/index.html") return true end function) server.UseRouter(new Http.CorsMiddleware()) server.UseRouter(homeRouter) server.UseRouter(new Http.StateApiRouter()) server.UseRouter(new Http.PreferencesRouter()) server.UseRouter(new Http.InvidiousRouter()) server.UseRouter(new Http.PlayQueueRouter()) server.UseRouter(new Http.SearchHistoryRouter()) server.UseRouter(new Http.PlayletLibUrlsRouter()) server.UseRouter(new Http.HttpStaticFilesRouter("/", "libpkg:/www", false, false, false)) server.UseRouter(new Http.HttpStaticFilesRouter("/config", "libpkg:/config", false, false, false)) server.UseRouter(new Http.HttpStaticFilesRouter("/logs", "cachefs:/logs", false, false)) #if DEBUG server.UseRouter(new Http.HttpStaticFilesRouter("/debug/libpkg", "libpkg:/", true, true, false)) server.UseRouter(new Http.HttpStaticFilesRouter("/debug/pkg", "pkg:/", true, true)) server.UseRouter(new Http.HttpStaticFilesRouter("/debug/tmp", "tmp:/", true, true)) server.UseRouter(new Http.HttpStaticFilesRouter("/debug/cachefs", "cachefs:/", true, true)) server.UseRouter(new Http.HttpStaticFilesRouter("/debug/common", "common:/", true, true)) #end if end function