startServer method
start dox server
await Dox().startServer();
Implementation
Future<void> startServer() async {
checkAppKey();
addProviders(config.providers);
GroupIdentity? group = _group;
if (group != null) {
// an isolate of its own group: the primary started it, so it only
// serves. It does not start isolates, watch signals or exit.
isWebServer = true;
await GroupWorker.run(group);
return;
}
_totalIsolate ??= Dox().config.totalIsolate;
int isolatesToSpawn = _totalIsolate!;
/// stop here, before any isolate starts, when the native server can
/// not run. The error says why and how to fix it.
NativeHttpServer.ensureAvailable();
/// a bad certificate file stops the start here, once. Else every
/// isolate fails on it and is started again, in a loop.
await DoxServer().checkCertificate();
/// Windows has no SO_REUSEPORT: one isolate owns the native listener.
if (Platform.isWindows && isolatesToSpawn > 1) {
Logger.info(
'Windows: the native server runs on one isolate',
null,
'server',
);
isolatesToSpawn = 1;
}
isolateCount = isolatesToSpawn;
isWebServer = true;
// each isolate group has its own slots, so there the warning is only
// for the fallback
bool tryGroups = config.flags.isolateGroups && isolatesToSpawn > 1;
if (!tryGroups) warnIsolateSlots(isolatesToSpawn, IsolateSlots.available);
if (isolatesToSpawn > 1) {
bool groups = await _spawnIsolates(isolatesToSpawn);
if (tryGroups && !groups) {
warnIsolateSlots(isolatesToSpawn, IsolateSlots.available);
}
}
await startProviders();
warnWebSocketOrigin();
warnCorsCredentials();
DoxServer().setResponseHandler(config.responseHandler);
HttpServer server = await DoxServer().listen(
DoxServer.portFor(config.serverPort),
address: DoxServer.hostFor(config.host),
);
Logger.info(
'Server started at ${serverUrl(server)} with $isolatesToSpawn isolate '
'(native)',
null,
'server',
);
_watchSignals();
}