serving library
Running a router as a server, including shutting one down.
import 'package:dust_server/serving.dart';
final server = await serve(app, InternetAddress.anyIPv4, 8080);
await ProcessSignal.sigterm.watch().first;
await server.close(drain: const Duration(seconds: 15));
Everything here is also exported from package:dust_server/server.dart.
Classes
- BackgroundTasks
- Work that outlives the response that started it.
- ServerHandle
- A running server that can be stopped without dropping work.
- ServerIsolates
- A cluster of isolates all serving one port.
Constants
-
defaultRevalidatedFiles
→ const Set<
String> - Files a build regenerates without putting a content hash in their name.
Functions
-
serve(
Router router, InternetAddress address, int port, {SecurityContext? securityContext, BackgroundTasks? background}) → Future< ServerHandle> -
Serves
router, counting requests so shutdown can wait for them. -
serveIsolates(
RouterFactory factory, InternetAddress address, int port, {required int isolates, void onIsolateError(Object? error, Object? stackTrace)?}) → Future< ServerIsolates> -
Serves
factoryfromisolatesisolates, all sharing one port. -
singlePageApp(
String file) → Handler - Serves one file for every document request, for a single-page application.
-
staticFiles(
String directory, {bool html = false, String? defaultDocument = 'index.html', Set< String> revalidate = defaultRevalidatedFiles, Duration immutableFor = const Duration(days: 365), bool crossOriginIsolated = false, bool listDirectories = false, bool serveFilesOutsidePath = false}) → Handler -
Serves the files under
directory.
Typedefs
- RouterFactory = Router Function()
- Builds the application for one isolate.