You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not able to consume the api through Flutter Web (just mobile) because it points out that it doesn't have cors, I tried to implement custom ones but it didn't work, any ideas?
( i even tried to force https but do not work too in the Web version)
My API:
import 'dart:async';
import 'dart:io';
import 'package:backend/api/login_api.dart';
import 'package:backend/api/pendency_api.dart';
import 'package:backend/services/login_service.dart';
import 'package:backend/services/pendency_service.dart';
import 'package:mysql_client/mysql_client.dart';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_cors_headers/shelf_cors_headers.dart';
import 'infra/database/mysql_config.dart';
import 'infra/middleware_interception.dart';
void main(List<String> args) async {
SecurityContext getSecurityContext() { // Bind with a secure HTTPS connection
final chain = Platform.script.resolve('certificates/server_chain.pem').toFilePath();
final key = Platform.script.resolve('certificates/server_key.pem').toFilePath();
return SecurityContext()
..useCertificateChain(chain)
..usePrivateKey(key, password: 'dartdart');
}
final ip = 'localhost'; //InternetAddress.anyIPv4;
print("Connecting to mysql server...");
final mysqlConnection = await createMySQLConnection();
var pendencyService = PendencyService(mysqlConnection);
var loginService = LoginService(mysqlConnection);
var cascadeHandler = Cascade()
.add(PendencyApi(pendencyService).handler)
.add(LoginApi(loginService).handler)
.handler;
final handler = Pipeline()
.addMiddleware(corsHeaders())
.addMiddleware(MiddlewareInterception.contenTypeJson)
.addMiddleware(MiddlewareInterception.cors)
.addHandler(cascadeHandler);
final port = int.parse(Platform.environment['PORT'] ?? '8080');
final server = await serve(handler, ip, port, securityContext: getSecurityContext());
print('Server listening on port ${server.port}');
setupExitHandlers(server, mysqlConnection);
}
The text was updated successfully, but these errors were encountered:
I'm not able to consume the api through Flutter Web (just mobile) because it points out that it doesn't have cors, I tried to implement custom ones but it didn't work, any ideas?
( i even tried to force https but do not work too in the Web version)
My API:
The text was updated successfully, but these errors were encountered: