O'Reilly logo

Dart: Scalable Application Development by Ivo Balbaert, Sergey Akopkokhyants, Davy Mitchell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Securing a server

Open the server.dart file and type the following lines:

import 'dart:io';

main() {
  var pkcertDB = Platform.script.resolve('pkcert').toFilePath();
  SecureSocket.initialize(database: pkcertDB,
    password: 'changeit');

  HttpServer
  .bindSecure(InternetAddress.ANY_IP_V6, 8443,
    certificateName: 'localhost_cert')
  .then((server) {
    server.listen((HttpRequest request) {
      request.response.write('Hello, world!');
      request.response.close();
    });
  });
}

This is an implementation of the well-known Hello, World! example. I always keep the password of my certificate in the code only for demonstration purposes. Please keep your password in an external encrypted file. The code of the server is pretty straightforward. One small exception is that it references ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required