Skip to content

Instantly share code, notes, and snippets.

@ThomasLocke
Created October 12, 2014 14:11
Show Gist options
  • Save ThomasLocke/5f5335382c40d997fbce to your computer and use it in GitHub Desktop.
Save ThomasLocke/5f5335382c40d997fbce to your computer and use it in GitHub Desktop.
shelfmiddleware.cors.dart
library shelfmiddleware.cors;
import 'headers.dart';
import 'package:shelf/shelf.dart' as shelf;
shelf.Middleware addCORSHeaders = shelf.createMiddleware(requestHandler: _options, responseHandler: _cors);
shelf.Response _options(shelf.Request request) => (request.method == 'OPTIONS') ?
new shelf.Response.ok(null, headers: CORSHeader) : null;
shelf.Response _cors(shelf.Response response) => response.change(headers: CORSHeader);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment