import 'dart:io'; import 'package:mysql1/mysql1.dart'; import 'package:mess_api/config.dart'; Future testDbConnection() async { final settings = ConnectionSettings( host: DBConfig.dbHost, port: DBConfig.dbPort, user: DBConfig.dbUser, password: DBConfig.dbPassword, db: DBConfig.dbName, ); final conn = await MySqlConnection.connect(settings); final results = await conn.query( 'SELECT test_number FROM test_table LIMIT 1', ); if (results.isEmpty) { throw Exception('DB CONNECT FAIL: no data'); } final value = results.first['test_number']; if (value != 777) { throw Exception('DB CONNECT FAIL: value=$value'); } print('DB CONNECT OK (777)'); await conn.close(); } void main() async { await testDbConnection(); final server = await HttpServer.bind( InternetAddress.anyIPv4, AppConfig.port, ); print('API server running on http://localhost:${AppConfig.port}'); await for (HttpRequest request in server) { request.response ..statusCode = HttpStatus.ok ..write('ok') ..close(); } }