Skip to content
pubscout

shelf_cors_headers

0.1.5, released 4 years ago by an unverified publisher

CORS headers middleware for Shelf.

WASM-ready
$ flutter pub add shelf_cors_headers
Source repository

What it does

A Shelf middleware to add CORS headers to shelf responses. It handles preflight requests, allows overriding default headers, and supports custom origin checker functions.

AI-written summary of version 0.1.5, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You are building a Shelf backend that needs to handle CORS headers for web clients.
  • You need to handle preflight requests automatically in a Shelf application.

Skip it when

  • You are not using the Shelf package for your backend/server.

Strengths

  • Handles preflight requests automatically
  • Allows custom origin checkers such as originOneOf
  • Easy to integrate into the Shelf Pipeline

Weaknesses

  • Limited to the Shelf ecosystem

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1

not documented

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

void main() async {
  var handler = const Pipeline()
      .addMiddleware(corsHeaders())
      .addHandler(_requestHandler);

  await serve(handler, 'localhost', 8080);
}

Response _requestHandler(Request request) {
  return Response.ok('Request for "${request.url}"');
}

Alternatives

Packages that do the same job and could replace shelf_cors_headers.

Works with

Packages commonly used together with shelf_cors_headers: ones it builds on, ones built on it, and its own family.