The Mission Control server: instance folders, ports, folder paths and project rules
moon add moonrockz/mission-control-serverasync fn main {
@async.with_task_group(reads => {
@server.serve(options, reads~, running => {
@stdio.stdout.write("\{running.address()}\n") catch { _ => () }
})
@env.exit(0)
})
}let server = @server.find_or_start(folder, {
program: "/usr/local/bin/mission-control",
args: ["serve", "--instance", "stable"],
})
let added = server.call(@app.add_project, { path: "/code/docs" })
println(server.link(Browser, Some(added.project.id)))| Case | The server |
|---|---|
| Answers(server) | The program on the port of server.json says that it is this instance. |
| Silent(name) | It does not answer for 1 to 2 seconds, or it does not end in 10 seconds after a stop. |
| NewerFormat(name, format) | It is from a newer version, and this version cannot read its server.json. |
| Request | Login | Reply |
|---|---|---|
| GET /?access_token=<token> | the token of a link | A page that keeps the cookie and the view key, and then shows the UI. |
| GET /, GET /app.js | cookie | The page of the UI and its script. |
| GET /session | cookie, and view key in Authorization: Bearer | 204, or 403 when the session does not exist. |
| /hub, /hub/negotiate | cookie, and view key in Authorization: Bearer or access_token | The SignalR hub, with the commands and the events. A message has 32768 bytes and 64 levels of JSON at most. |
| GET /control/status | secret | {"app":"mission-control","instance":…,"version":…,"views":…} |
| POST /control/link?surface=&project= | secret | {"url":…}. surface is browser or desktop. project can be absent. |
| POST /control/call?command=&request= | secret | 200 with the reply of the command, or 422 with the text of a refusal. |
| POST /control/stop | secret | 202, and then the server stops. |
pub(all) suberror ServeError {
AlreadyRunning
NotStarted(StartFailure)
Ended(String)
} derive(Eq, Debug)pub(all) enum FoundServer {
Answers(RunningServer)
Silent(InstanceName)
NewerFormat(InstanceName, Int)
}pub struct RunningServer {
// private fields
}async fn[Req : ToJson, Res : FromJson] RunningServer::call(self : RunningServer, command : Command[Req, Res], request : Req) -> Res raise ServerCallErrorasync fn RunningServer::call_json(self : RunningServer, name : String, request : Json) -> Json raise ServerCallErrorasync fn RunningServer::link(self : RunningServer, surface : Surface, project : ProjectId?) -> String raise ServerCallErrorpub(all) struct ServeOptions {
folder : InstanceFolder
port : PortChoice
version : Version
} derive(Eq, Debug)async fn find_or_start(folder : InstanceFolder, starter : Starter) -> RunningServer raise StartErrorasync fn[X] serve(options : ServeOptions, ready : async (RunningServer) -> Unit noraise, reads~ : TaskGroup[X]) -> Unit raise ServeError@async.with_task_group(reads => {
serve(options, reads~, running => {
@stdio.stdout.write("\{running.address()}\n") catch { _ => () }
})
@env.exit(0)
})Install
Download zipThe Mission Control server: instance folders, ports, folder paths and project rules