Skip to content

Commit 3ab6ed1

Browse files
committed
update cors
1 parent 384d028 commit 3ab6ed1

9 files changed

+21
-22
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Changed
1212
- URL Design matching now respects the base URL
13-
- Allo null to be returned by error interceptors
13+
- Allow null to be returned by error interceptors
1414

1515
### Fixed
16-
- StandardUriDesign working incosistently depending on the trailing slash in the path
16+
- StandardUriDesign working inconsistently, depending on the trailing slash in the path
1717

1818
## [8.1.0] - 2024-08-29
1919
### Added

lib/client.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/// representing the most common use cases of resource fetching and manipulation.
2222
/// It can conveniently construct and parse JSON:API documents and URIs.
2323
/// The [RoutingClient] should be your default choice.
24-
library client;
24+
library;
2525

2626
export 'package:json_api/src/client/client.dart';
2727
export 'package:json_api/src/client/request.dart';

lib/document.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// JSON:API Document model.
2-
library document;
2+
library;
33

44
export 'package:json_api/src/document/error_object.dart';
55
export 'package:json_api/src/document/inbound_document.dart';

lib/http.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Common HTTP utilities for JSON:API clients and servers.
22
/// WARNING: This library is in beta stage. The API is subject to change.
3-
library http;
3+
library;
44

55
export 'package:json_api/src/http/status_code.dart';

lib/query.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// A set of builders/parsers for special query parameters used in JSON:API.
2-
library query;
2+
library;
33

44
export 'package:json_api/src/query/fields.dart';
55
export 'package:json_api/src/query/include.dart';

lib/routing.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// Routing describes the design of URLs on the server.
22
/// See https://jsonapi.org/recommendations/#urls
3-
library routing;
3+
library;
44

55
export 'package:json_api/src/routing/standard_uri_design.dart';
66
export 'package:json_api/src/routing/target.dart';

lib/server.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// JSON:API server on top of dart:io.
22
/// WARNING: This library is in beta stage. The API is subject to change.
3-
library server;
3+
library;
44

55
export 'package:json_api/src/server/controller.dart';
66
export 'package:json_api/src/server/cors_middleware.dart';

lib/src/server/cors_middleware.dart

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import 'package:http_interop/http_interop.dart';
2+
import 'package:http_interop_middleware/http_interop_middleware.dart';
23

3-
Handler corsMiddleware(Handler handler) =>
4-
(Request request) async => switch (request.method) {
4+
final corsMiddleware = middleware(
5+
onRequest: (rq) async => switch (rq.method) {
56
'options' => Response(
67
204,
78
Body(),
89
Headers.from({
910
'Access-Control-Allow-Methods':
10-
request.headers['Access-Control-Request-Method'] ??
11+
rq.headers['Access-Control-Request-Method'] ??
1112
const ['POST', 'GET', 'DELETE', 'PATCH', 'OPTIONS'],
1213
'Access-Control-Allow-Headers':
13-
request.headers['Access-Control-Request-Headers'] ??
14-
const ['*'],
14+
rq.headers['Access-Control-Request-Headers'] ?? const ['*'],
1515
})),
16-
_ => await handler(request)
17-
}
18-
..headers.addAll({
19-
'Access-Control-Allow-Origin': [
20-
request.headers['origin']?.last ?? '*'
21-
],
22-
'Access-Control-Expose-Headers': const ['Location'],
23-
});
16+
_ => null
17+
},
18+
onResponse: (rs, rq) async => rs
19+
..headers.addAll({
20+
'Access-Control-Allow-Origin': [rq.headers['origin']?.last ?? '*'],
21+
'Access-Control-Expose-Headers': const ['Location'],
22+
}));

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_api
2-
version: 9.0.0-alpha.5
2+
version: 9.0.0-alpha.6
33
homepage: https://github.com/f3ath/json-api-dart
44
description: A framework-agnostic implementations of JSON:API Client and Server. Supports JSON:API v1.0 (https://jsonapi.org)
55
environment:

0 commit comments

Comments
 (0)