-
Notifications
You must be signed in to change notification settings - Fork 42
Server Configuration
If you invoke the start()
method with no arguments, the server will be configured with default values:
Argument | Default Value |
---|---|
host | "0.0.0.0" |
port | 8080 |
protocol | http |
In order to start a secure server (https), you should specify the optional secureOptions
argument
when calling the start ()
method.
The secureOptions
is a Map<Symbol, dynamic>
that will be forwarded to the HttpServer.bindSecure()
method:
import 'package:redstone/redstone.dart' as app;
main() {
app.setupConsoleLog();
app.start(secureOptions: {#certificateName: "CN=RedStone"});
}
See the https.dart
for a working example.
If you need to serve static files, you can use the shelf_static package:
import 'package:redstone/redstone.dart' as app;
import 'dart:io' show Platform;
import "package:path/path.dart" as Path;
import 'package:shelf_static/shelf_static.dart';
main() {
String scriptPath = Path.dirname(Path.fromUri(Platform.script));
String pathToWeb = Path.normalize("$scriptPath/../web");
app.setShelfHandler(createStaticHandler(pathToWeb,
defaultDocument: "index.html",
serveFilesOutsidePath: true));
app.setupConsoleLog();
app.start();
}
Redstone.dart provides a helper method to set a simple log handler, which outputs the messages to the console:
app.setupConsoleLog();
By default, the log level is setted to INFO, which logs the startup process and errors. If you want to see all the log messages, you can set the level to ALL:
import 'package:logging/logging.dart';
main() {
app.setupConsoleLog(Level.ALL);
...
}
If you want to output the messages to a different place (for example, a file), you can define your own log handler:
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((LogRecord rec) {
...
});
-
Quick Start Guide
-
Reference
-
Serialization
-
Databases
-
MVC
-
Web Sockets