-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
every route has to be redeclared with the options method to pass the CORS #6
Comments
Kindly provide more info on what you are trying to achieve |
sure, for instance, if you run this code: import 'dart:io';
import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_router/shelf_router.dart';
import 'package:shelf_cors_headers/shelf_cors_headers.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(corsHeaders())
.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}');
} Then when the browser is trying to call the OPTIONS on the given route, a route not found will be returned. ..options('/', _rootHandler)
..options('/echo/<message>', _echoHandler); So that can each routes in your router pass the CORS. It's not an issue, i was just wondering if it's possible for this middleware to behave like CORS in python's FLASK |
I think raise this with the shelf router team, this seems like a routing issue |
Any update?
But it doesn't work the post request doesn't happen. |
If you want any help, you will probably have to give more info, code sample, logs, d'art and plugin version, etc.... |
When the Flutter app tried to connect the dart server with the POST method, it will send a request with the OPTIONS method to the dart server and I need a solution to handle this request.
|
Hey, first of all thanks for this plugin
Is this behavior expected?
Is there anyway to add this feature like for python's Flask CORS:
for instance?
The text was updated successfully, but these errors were encountered: