Skip to content

Commit f4d1f1c

Browse files
committed
Update example for origins
1 parent 3a9b3bc commit f4d1f1c

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ This package can be used as a library. You can use it in your framework using:
3939

4040
The _allowedMethods_ and _allowedHeaders_ options are case-insensitive.
4141

42-
You don't need to provide both _allowedOrigins_ and _allowedOriginsPatterns_. If one of the strings passed matches, it is considered a valid origin.
42+
You don't need to provide both _allowedOrigins_ and _allowedOriginsPatterns_. If one of the strings passed matches, it is considered a valid origin. A wildcard in allowedOrigins will be converted to a pattern.
4343

4444
If `['*']` is provided to _allowedMethods_, _allowedOrigins_ or _allowedHeaders_ all methods / origins / headers are allowed.
4545

46+
> Note: Allowing a single static origin will improve cacheability.
47+
4648
### Example: using the library
4749

4850
```php
@@ -54,7 +56,7 @@ $cors = new CorsService([
5456
'allowedHeaders' => ['x-allowed-header', 'x-other-allowed-header'],
5557
'allowedMethods' => ['DELETE', 'GET', 'POST', 'PUT'],
5658
'allowedOrigins' => ['http://localhost'],
57-
'allowedOriginsPatterns' => ['/localhost:\d/'],
59+
'allowedOriginsPatterns' => ['/localhost:\d/', 'https://*.example.com'],
5860
'exposedHeaders' => false,
5961
'maxAge' => false,
6062
'supportsCredentials' => false,

src/CorsService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ private function convertWildcardToPattern($pattern)
104104

105105
// Asterisks are translated into zero-or-more regular expression wildcards
106106
// to make it convenient to check if the strings starts with the given
107-
// pattern such as "library/*", making any string check convenient.
107+
// pattern such as "*.example.com", making any string check convenient.
108108
$pattern = str_replace('\*', '.*', $pattern);
109109

110110
return '#^' . $pattern . '\z#u';

0 commit comments

Comments
 (0)