PageService

Give your tool a web page of its own, with a live channel both ways between the page and your program.

ServeAsync serves texts by route and files from a folder, on this computer only, and gives a Page. The page's side is one script, /shotsystem/live.js: ShotLive.on, ShotLive.send and ShotLive.onState, and it reconnects by itself. The editor window's own pieces are served at /ui/common/, so a page can look and move like the Explorer.

ShotInstanceservicenot creatableWeb

A service: write use PageService.

Example

Serve two pagesShotScript
-- Serves pages on this computer: one from text and one from a folder on disk, then reads both back.
use FileService
use HttpService
use PageService
FileService:WriteAsync("Site/todo.txt", "buy milk")
local page, why = PageService:ServeAsync({ Folder = "Site", Pages = { ["/"] = "<h1>Notes</h1>" } })
if not page then
	error("couldn't serve the pages: " .. tostring(why))
end
-- files need no key, so the address is the Url before its ?k=...
local base = string.match(page.Url, "^[^?]*") or page.Url

for _, route in { "", "todo.txt" } do
	local answer = HttpService:FetchAsync({ Url = base .. route })
	if answer then
		print("/" .. route .. ": " .. answer.Body .. " (" .. tostring(answer.Headers["content-type"]) .. ")")
	end
end
print("a child of PageService: " .. tostring(page.Parent == PageService))
page:Destroy()
FileService:RemoveAsync("Site")
What it printedOutput
/: <h1>Notes</h1> (text/html; charset=utf-8)
/todo.txt: buy milk (text/plain; charset=utf-8)
a child of PageService: true

Methods

NameArgumentsReturnsDescription
ServeAsync
yields
(options: PageOptions?)(Page?, string?)Waits until a page server runs on this computer only, serving Pages texts and Folder files, on the first free port from Port.
From ShotInstance 33