This a typical code provided by Dart for a server using Shelf
package :
import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_router/shelf_router.dart';
// Configure routes.
final _router = Router()
..get('/', _rootHandler)
..get('/echo/<message>', _echoHandler);
Response _rootHandler(Request req) {
return Response.ok('Hello, World!\n');
}
Response _echoHandler(Request request) {
final message = request.params['message'];
return Response.ok('$message\n');
}
void main(List<String> args) async {
// Use any available host or container IP (usually `0.0.0.0`).
final ip = InternetAddress.anyIPv4;
// Configure a pipeline that logs requests.
final _handler = Pipeline().addMiddleware(logRequests()).addHandler(_router);
// For running in containers, we respect the PORT environment variable.
final port = int.parse(Platform.environment['PORT'] ?? '8080');
final server = await serve(_handler, ip, port);
print('Server listening on port ${server.port}');
}
What/How should it need to be modified to support secure connections (HTTPS) only?
I don't really understand about certificates, so if you could give a detail explanation about how to generate/buy them and how to link them to server or any reference for dummies it'd be great.
P.S.: My host is a Linux distro (Manjaro) running the following Docker containers: a file server (Dart with Shelf) and GraphQL server (Postgraphile). Do I need to make configurations for every service running in my host?