Self HTTP test not OK!
Closed this issue · 1 comments
gaddlord commented
I am getting this error:
"Self HTTP test not OK!"
while calling
await letsEncrypt.startSecureServer()
having this simple server:
import 'dart:io';
import 'dart:async' show runZonedGuarded;
import 'package:path/path.dart' show join, dirname;
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf_gzip/shelf_gzip.dart';
import 'package:shelf_static/shelf_static.dart';
import 'package:shelf_letsencrypt/shelf_letsencrypt.dart';
Response _echoHandler(Request request) {
final message = request.params['message'];
return Response.ok('$message\n');
}
void main(List<String> args) async {
final ip = InternetAddress.anyIPv4;
final pathToBuild = join(dirname(Platform.script.toFilePath()), '../../../',
'mtg.studio.project/ui/build/web');
final staticHandler =
createStaticHandler(pathToBuild, defaultDocument: 'index.html');
// Configure routes.
final app = Router();
app.get('/sample/route/<message>', _echoHandler);
runZonedGuarded(() async {
final handlers = Pipeline()
.addMiddleware(logRequests())
.addMiddleware(gzipMiddleware)
.addHandler(Cascade().add(staticHandler).add(app).handler);
// For running in containers, we respect the PORT environment variable.
final port = int.parse(Platform.environment['PORT'] ?? '3030');
final domain = 'domain.com';
final domainEmail = 'support@domain.com';
final certificatesDirectory = '.'; // /etc/letsencrypt/live';
// The Certificate handler, storing at `certificatesDirectory`.
final certificatesHandler =
CertificatesHandlerIO(Directory(certificatesDirectory));
// The Let's Encrypt integration tool in `staging` mode:
final LetsEncrypt letsEncrypt =
LetsEncrypt(certificatesHandler, production: false);
// final server = await serve(handlers, ip, port);
final servers = await letsEncrypt.startSecureServer(
handlers,
domain,
domainEmail,
port: port,
securePort: 3443,
);
var server = servers[0]; // HTTP Server.
var serverSecure = servers[1]; // HTTPS Server.
// Enable gzip:
server.autoCompress = true;
serverSecure.autoCompress = true;
print('☀️Serving at http://${server.address.host}:${server.port}');
print(
'☀️Serving at https://${serverSecure.address.host}:${serverSecure.port}');
}, (e, stackTrace) => print('🐞Server error: $e $stackTrace'));
}
gmpassos commented
Fixed