shelf_cors_headers 0.1.5 copy "shelf_cors_headers: ^0.1.5" to clipboard
shelf_cors_headers: ^0.1.5 copied to clipboard

CORS headers middleware for Shelf.

example/shelf_cors_headers_example.dart

import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart';
import 'package:shelf_cors_headers/shelf_cors_headers.dart';

void main() async {
  final overrideHeaders = {
    ACCESS_CONTROL_ALLOW_ORIGIN: 'example.com',
    'Content-Type': 'application/json;charset=utf-8'
  };

  var handler = const Pipeline()
      .addMiddleware(corsHeaders(headers: overrideHeaders))
      .addHandler(_echoRequest);

  var server = await serve(handler, 'localhost', 8080);

  // Enable content compression
  server.autoCompress = true;

  print('Serving at http://${server.address.host}:${server.port}');
}

Response _echoRequest(Request request) {
  return Response.ok('Request for "${request.url}"');
}
38
likes
140
pub points
95%
popularity

Publisher

unverified uploader

CORS headers middleware for Shelf.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

shelf

More

Packages that depend on shelf_cors_headers