start static method
- FakeServerOptions options = const FakeServerOptions(),
Starts a fake on 127.0.0.1 with a free port.
The contract checks use docs/api/ above the working directory, or the embedded copy
where the repository cannot be read (ContractSchemas.load). Throws the error of
HttpServer.bind.
Implementation
static Future<FakeServer> start({
FakeServerOptions options = const FakeServerOptions(),
}) async {
final contract = ContractSchemas.load();
final world = FakeWorld(now: options.now);
final verifier = DpopVerifier(now: world.now);
final http = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
final base = Uri.parse('http://127.0.0.1:${http.port}');
final gateway = GatewayFake(
world: world,
contract: contract,
verifier: verifier,
timings: options.timings,
baseUri: () => base,
);
final faults = FaultPlan(gateway);
final rest = RestFake(
world: world,
contract: contract,
verifier: verifier,
faults: faults,
);
registerAuthHandlers(rest, accessTokenTtl: options.accessTokenTtl);
registerSyncHandlers(rest);
registerStructureHandlers(rest);
registerMessageHandlers(rest);
registerPersonalHandlers(rest);
registerRunHandlers(rest);
registerSelfHandlers(rest);
registerFileHandlers(rest);
final actions = ActionCatalog.load();
final audit = FakeAuditLog();
registerAdminHandlers(rest, actions, audit);
registerAccessHandlers(rest, actions, audit);
registerAuditHandlers(rest, actions, audit);
registerHostHandlers(rest, actions, audit);
registerTerminalHandlers(rest);
registerThreadViewHandlers(rest);
registerAgentHandlers(rest, actions, audit);
registerHintHandlers(rest, actions);
registerStatsHandlers(rest, actions);
registerNotifyHandlers(rest, actions);
registerSearchHandlers(rest);
registerAgentUiHandlers(rest);
final server = FakeServer._(
http,
world,
rest,
gateway,
faults,
verifier,
contract,
actions,
audit,
TerminalStreamFake(world: world, verifier: verifier, baseUri: () => base),
);
http.listen(server._onRequest);
return server;
}