Skip to main content

cors_enabler 0.9.1+2 copy "cors_enabler: ^0.9.1+2" to clipboard
cors_enabler: ^0.9.1+2 copied to clipboard

A CORS proxy to make any API server CORS-compliant.

example/cors_enabler.dart

import 'dart:io';

import 'package:cors_enabler/cors_enabler.dart';

void main(List<String> arguments) async {
  // Simple runner for the CORS proxy.
  if (arguments.isEmpty) {
    print('Usage: dart run example/cors_enabler.dart <target-url> [port]');
    exit(2);
  }

  final targetArg = arguments[0];
  final targetUri = Uri.tryParse(targetArg);
  if (targetUri == null ||
      !(targetUri.scheme == 'http' || targetUri.scheme == 'https')) {
    print('Error: target must be a valid http or https URL.');
    exit(2);
  }

  final port = arguments.length > 1 ? int.tryParse(arguments[1]) ?? 8080 : 8080;
  final proxy = CorsProxy(target: targetUri, port: port);
  await proxy.start();
  final boundPort = proxy.boundPort;
  print('CORS proxy listening on http://localhost:$boundPort');

  // Keep running until the user terminates (Ctrl-C)
  ProcessSignal.sigint.watch().listen((_) async {
    print('Shutting down...');
    await proxy.stop();
    exit(0);
  });
}
1
likes
160
points
12
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A CORS proxy to make any API server CORS-compliant.

Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on cors_enabler