angel_cors 2.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 78

cors #

Pub build status

Angel CORS middleware. Port of the original Express CORS middleware.

For complete example usage, see the example file.

2.0.0 #

  • Updates for Dart 2 and Angel 2.

example/example.dart

import 'dart:async';
import 'package:angel_cors/angel_cors.dart';
import 'package:angel_framework/angel_framework.dart';

Future configureServer(Angel app) async {
  // The default options will allow CORS for any request.
  // Combined with `fallback`, you can enable CORS application-wide.
  app.fallback(cors());

  // You can also enable CORS for a single route.
  app.get(
    '/my_api',
    chain([
      cors(),
      (req, res) {
        // Request handling logic here...
      }
    ]),
  );

  // Likewise, you can apply CORS to a group.
  app.chain([cors()]).group('/api', (router) {
    router.get('/version', (req, res) => 'v0');
  });

  // Of course, you can configure CORS.
  // The following is just a subset of the available options;
  app.fallback(cors(
    CorsOptions(
      origin: 'https://pub.dartlang.org', successStatus: 200, // default 204
      allowedHeaders: ['POST'],
      preflightContinue: false, // default false
    ),
  ));

  // You can specify the origin in different ways:
  CorsOptions(origin: 'https://pub.dartlang.org');
  CorsOptions(origin: ['https://example.org', 'http://foo.bar']);
  CorsOptions(origin: RegExp(r'^foo\.[^$]+'));
  CorsOptions(origin: (String s) => s.length == 4);

  // Lastly, you can dynamically configure CORS:
  app.fallback(dynamicCors((req, res) {
    return CorsOptions(
      origin: [
        req.headers.value('origin') ?? 'https://pub.dartlang.org',
        RegExp(r'\.com$'),
      ],
    );
  }));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  angel_cors: ^2.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:angel_cors/angel_cors.dart';
  
Version Uploaded Documentation Archive
2.0.0 Feb 7, 2019 Go to the documentation of angel_cors 2.0.0 Download angel_cors 2.0.0 archive
1.0.0+2 Nov 18, 2017 Go to the documentation of angel_cors 1.0.0+2 Download angel_cors 1.0.0+2 archive
1.0.0+1 Apr 15, 2017 Go to the documentation of angel_cors 1.0.0+1 Download angel_cors 1.0.0+1 archive
1.0.0 Apr 10, 2017 Go to the documentation of angel_cors 1.0.0 Download angel_cors 1.0.0 archive
1.0.0-dev+2 Dec 21, 2016 Go to the documentation of angel_cors 1.0.0-dev+2 Download angel_cors 1.0.0-dev+2 archive
1.0.0-dev+1 Dec 5, 2016 Go to the documentation of angel_cors 1.0.0-dev+1 Download angel_cors 1.0.0-dev+1 archive
1.0.0-dev Dec 5, 2016 Go to the documentation of angel_cors 1.0.0-dev Download angel_cors 1.0.0-dev archive
Popularity:
Describes how popular the package is relative to other packages. [more]
55
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
78
Learn more about scoring.

We analyzed this package on Apr 19, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14

Platforms

Detected platforms: Flutter, other

Primary library: package:angel_cors/angel_cors.dart with components: io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
angel_framework ^2.0.0-alpha 2.0.0-rc.6
Transitive dependencies
angel_container 1.0.4
angel_http_exception 1.1.0
angel_model 1.0.2
angel_route 3.0.6
charcode 1.1.2
code_buffer 1.0.1
collection 1.14.11
combinator 1.1.0
convert 2.1.1
crypto 2.0.6
dart2_constant 1.0.2+dart2
file 5.0.7
http2 1.0.0
http_parser 3.1.3
http_server 0.9.8+1
intl 0.15.8
logging 0.11.3+2
matcher 0.12.5
merge_map 1.0.2
meta 1.1.7
mime 0.9.6+2
mock_request 1.0.5
path 1.6.2
quiver 2.0.3
quiver_hashcode 2.0.0
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.4
term_glyph 1.1.0
tuple 1.0.2
typed_data 1.1.6
uuid 2.0.1
Dev dependencies
angel_test ^2.0.0
http ^0.12.0
pedantic ^1.0.0 1.5.0
test ^1.0.0