-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added CORS support to API * Changed order so CORS will still work if throttle hit * Added APP_CORS_ALLOWED_ORIGINS env option * Fixed typo * Clarified header comments * More clarification * DIsable CORS allowed origins by default to replicate existing behavior * Change variable name to be clearer
- Loading branch information
Showing
5 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/** | ||
* --------------------------------------------------------------------- | ||
* THIS IS $allowed_origins code IS NOT PART OF THE ORIGINAL CORS PACKAGE. | ||
* IT IS A MODIFICATION BY SNIPE-IT TO ALLOW ADDING ALLOWED ORIGINS VIA THE ENV. | ||
* --------------------------------------------------------------------- | ||
* | ||
* Since we don't really want people editing config files (lest they get | ||
* overwritten later), this enables the person managing the Snipe-IT | ||
* installation to modify these values without modifying the code. | ||
* | ||
* If APP_CORS_ALLOWED_ORIGINS is not set in the .env (for example if no one added it | ||
* after an upgrade from a previous version that didn't include it in the .env.example) or is null, | ||
* set it to * to allow all. If there is a value, either a single url or a comma-delimited | ||
* list of urls, explode that out into an array to whitelist just those urls. | ||
*/ | ||
|
||
$allowed_origins = env('CORS_ALLOWED_ORIGINS') !== null ? | ||
explode(',', env('CORS_ALLOWED_ORIGINS')) : []; | ||
|
||
/** | ||
* Original Laravel CORS package config file modifications end here | ||
* | ||
*/ | ||
|
||
|
||
return [ | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Laravel CORS | ||
|-------------------------------------------------------------------------- | ||
| | ||
| allowedOrigins, allowedHeaders and allowedMethods can be set to array('*') | ||
| to accept any value. | ||
| | ||
*/ | ||
|
||
'supportsCredentials' => false, | ||
'allowedOrigins' => $allowed_origins, | ||
'allowedOriginsPatterns' => [], | ||
'allowedHeaders' => ['*'], | ||
'allowedMethods' => ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'], | ||
'exposedHeaders' => [], | ||
'maxAge' => 0, | ||
|
||
]; |