blob: f2186ba30587831d52ae3c5ae3b5c61c5b66a272 [file] [log] [blame]
import 'dart:io';
import 'package:appengine/appengine.dart';
import 'package:logging/logging.dart';
final _log = Logger('server');
requestHandler(HttpRequest request) {
// Handle liveness checks, this is to show that the server is alive.
//
// The path for this is configured in app.yaml
if (request.requestedUri.path == '/liveness_check') {
request.response
..statusCode = 200
..write('server is alive')
..close();
return;
}
// Handle readiness checks, responding 200 OK, shows that we're ready to serve
// traffic. If we had to establish database connections and do other setup
// we might respond 503 until such time that we are ready.
//
// The path for this is configured in app.yaml
if (request.requestedUri.path == '/readiness_check') {
request.response
..statusCode = 200
..write('server is ready')
..close();
return;
}
// Log the request
_log.info('request for path: ${request.requestedUri.path}');
try {
if (request.requestedUri.path == '/error') {
throw Exception('Something bad happens when hitting this path');
}
} on Exception catch (e, st) {
// This will log the message to stackdriver logging along with the error
// and stack trace. This will also send error and stack trace to stackdriver
// error reporting service.
_log.severe('a bad thing happend', e, st);
}
// Respond hello world, when serving normal traffic.
request.response
..statusCode = 200
..write('Hello, world!')
..close();
}
main() async {
await withAppEngineServices(() async {
useLoggingPackageAdaptor();
await runAppEngine(requestHandler);
});
}