跨域设置
This commit is contained in:
parent
248a5232c0
commit
7b89e9bea2
@ -33,7 +33,8 @@
|
||||
"psr/container": "^1.1.1",
|
||||
"php-di/php-di": "^6",
|
||||
"doctrine/annotations": "^1.14",
|
||||
"webman/push": "^1.0"
|
||||
"webman/push": "^1.0",
|
||||
"webman/cors": "^1.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-event": "For better performance. "
|
||||
|
22
composer.lock
generated
22
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "925eb31b037c538d5ddaba7603395749",
|
||||
"content-hash": "cb9309ca73e56832131eeb8c02ae9170",
|
||||
"packages": [
|
||||
{
|
||||
"name": "doctrine/annotations",
|
||||
@ -1262,6 +1262,26 @@
|
||||
"description": "JSON Web Token (JWT) for webman plugin",
|
||||
"time": "2023-09-16T03:25:47+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webman/cors",
|
||||
"version": "v1.0.1",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://mirrors.cloud.tencent.com/repository/composer/webman/cors/v1.0.1/webman-cors-v1.0.1.zip",
|
||||
"reference": "a5396634fd2ee4e7b15abba0bab45f28e1c1ad02",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Webman\\Cors\\": "src"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"time": "2022-11-05T11:16:20+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webman/push",
|
||||
"version": "v1.0.16",
|
||||
|
4
config/plugin/webman/cors/app.php
Normal file
4
config/plugin/webman/cors/app.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
19
config/plugin/webman/cors/middleware.php
Normal file
19
config/plugin/webman/cors/middleware.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return [
|
||||
'' => [
|
||||
\Webman\Cors\CORS::class
|
||||
]
|
||||
];
|
@ -14,8 +14,9 @@
|
||||
|
||||
use Webman\Route;
|
||||
|
||||
|
||||
|
||||
|
||||
// 给所有OPTIONS请求设置跨域
|
||||
Route::options('[{path:.+}]', function (){
|
||||
return response('');
|
||||
});
|
||||
|
||||
|
||||
|
1
vendor/composer/autoload_psr4.php
vendored
1
vendor/composer/autoload_psr4.php
vendored
@ -12,6 +12,7 @@ return array(
|
||||
'app\\' => array($baseDir . '/app'),
|
||||
'Workerman\\' => array($vendorDir . '/workerman/workerman'),
|
||||
'Webman\\Push\\' => array($vendorDir . '/webman/push/src'),
|
||||
'Webman\\Cors\\' => array($vendorDir . '/webman/cors/src'),
|
||||
'Webman\\' => array($vendorDir . '/workerman/webman-framework/src'),
|
||||
'WebSocket\\' => array($vendorDir . '/textalk/websocket/lib'),
|
||||
'Tinywan\\Jwt\\' => array($vendorDir . '/tinywan/jwt/src'),
|
||||
|
5
vendor/composer/autoload_static.php
vendored
5
vendor/composer/autoload_static.php
vendored
@ -33,6 +33,7 @@ class ComposerStaticInitdf7b72b3aceadccf28975d51278ffb6d
|
||||
array (
|
||||
'Workerman\\' => 10,
|
||||
'Webman\\Push\\' => 12,
|
||||
'Webman\\Cors\\' => 12,
|
||||
'Webman\\' => 7,
|
||||
'WebSocket\\' => 10,
|
||||
),
|
||||
@ -118,6 +119,10 @@ class ComposerStaticInitdf7b72b3aceadccf28975d51278ffb6d
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/webman/push/src',
|
||||
),
|
||||
'Webman\\Cors\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/webman/cors/src',
|
||||
),
|
||||
'Webman\\' =>
|
||||
array (
|
||||
0 => __DIR__ . '/..' . '/workerman/webman-framework/src',
|
||||
|
23
vendor/composer/installed.json
vendored
23
vendor/composer/installed.json
vendored
@ -1331,6 +1331,29 @@
|
||||
"description": "JSON Web Token (JWT) for webman plugin",
|
||||
"install-path": "../tinywan/jwt"
|
||||
},
|
||||
{
|
||||
"name": "webman/cors",
|
||||
"version": "v1.0.1",
|
||||
"version_normalized": "1.0.1.0",
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://mirrors.cloud.tencent.com/repository/composer/webman/cors/v1.0.1/webman-cors-v1.0.1.zip",
|
||||
"reference": "a5396634fd2ee4e7b15abba0bab45f28e1c1ad02",
|
||||
"shasum": ""
|
||||
},
|
||||
"time": "2022-11-05T11:16:20+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Webman\\Cors\\": "src"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"install-path": "../webman/cors"
|
||||
},
|
||||
{
|
||||
"name": "webman/push",
|
||||
"version": "v1.0.16",
|
||||
|
13
vendor/composer/installed.php
vendored
13
vendor/composer/installed.php
vendored
@ -3,7 +3,7 @@
|
||||
'name' => 'workerman/webman',
|
||||
'pretty_version' => 'dev-main',
|
||||
'version' => 'dev-main',
|
||||
'reference' => '3350338e0749881038a3e9e064a551e992eb95ee',
|
||||
'reference' => '248a5232c064774459edbfc61a1c8794ba457dd0',
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
@ -265,6 +265,15 @@
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'webman/cors' => array(
|
||||
'pretty_version' => 'v1.0.1',
|
||||
'version' => '1.0.1.0',
|
||||
'reference' => 'a5396634fd2ee4e7b15abba0bab45f28e1c1ad02',
|
||||
'type' => 'library',
|
||||
'install_path' => __DIR__ . '/../webman/cors',
|
||||
'aliases' => array(),
|
||||
'dev_requirement' => false,
|
||||
),
|
||||
'webman/push' => array(
|
||||
'pretty_version' => 'v1.0.16',
|
||||
'version' => '1.0.16.0',
|
||||
@ -277,7 +286,7 @@
|
||||
'workerman/webman' => array(
|
||||
'pretty_version' => 'dev-main',
|
||||
'version' => 'dev-main',
|
||||
'reference' => '3350338e0749881038a3e9e064a551e992eb95ee',
|
||||
'reference' => '248a5232c064774459edbfc61a1c8794ba457dd0',
|
||||
'type' => 'project',
|
||||
'install_path' => __DIR__ . '/../../',
|
||||
'aliases' => array(),
|
||||
|
21
vendor/webman/cors/LICENSE
vendored
Normal file
21
vendor/webman/cors/LICENSE
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 webman
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
2
vendor/webman/cors/README.md
vendored
Normal file
2
vendor/webman/cors/README.md
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# cors
|
||||
CORS plugin for webman
|
12
vendor/webman/cors/composer.json
vendored
Normal file
12
vendor/webman/cors/composer.json
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "webman/cors",
|
||||
"type": "library",
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Webman\\Cors\\": "src"
|
||||
}
|
||||
}
|
||||
}
|
4
vendor/webman/cors/config/plugin/webman/cors/app.php
vendored
Normal file
4
vendor/webman/cors/config/plugin/webman/cors/app.php
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
19
vendor/webman/cors/config/plugin/webman/cors/middleware.php
vendored
Normal file
19
vendor/webman/cors/config/plugin/webman/cors/middleware.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return [
|
||||
'' => [
|
||||
\Webman\Cors\CORS::class
|
||||
]
|
||||
];
|
22
vendor/webman/cors/src/CORS.php
vendored
Normal file
22
vendor/webman/cors/src/CORS.php
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Webman\Cors;
|
||||
|
||||
use Webman\MiddlewareInterface;
|
||||
use Webman\Http\Response;
|
||||
use Webman\Http\Request;
|
||||
|
||||
class CORS implements MiddlewareInterface
|
||||
{
|
||||
public function process(Request $request, callable $next) : Response
|
||||
{
|
||||
$response = $request->method() == 'OPTIONS' ? response('') : $next($request);
|
||||
$response->withHeaders([
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Allow-Origin' => $request->header('origin', '*'),
|
||||
'Access-Control-Allow-Methods' => $request->header('access-control-request-method', '*'),
|
||||
'Access-Control-Allow-Headers' => $request->header('access-control-request-headers', '*'),
|
||||
]);
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
74
vendor/webman/cors/src/Install.php
vendored
Normal file
74
vendor/webman/cors/src/Install.php
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace Webman\Cors;
|
||||
|
||||
class Install
|
||||
{
|
||||
const WEBMAN_PLUGIN = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected static $pathRelation = array (
|
||||
'config/plugin/webman/cors' => 'config/plugin/webman/cors',
|
||||
);
|
||||
|
||||
/**
|
||||
* Install
|
||||
* @return void
|
||||
*/
|
||||
public static function install()
|
||||
{
|
||||
static::installByRelation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall
|
||||
* @return void
|
||||
*/
|
||||
public static function uninstall()
|
||||
{
|
||||
self::uninstallByRelation();
|
||||
}
|
||||
|
||||
/**
|
||||
* installByRelation
|
||||
* @return void
|
||||
*/
|
||||
public static function installByRelation()
|
||||
{
|
||||
foreach (static::$pathRelation as $source => $dest) {
|
||||
if ($pos = strrpos($dest, '/')) {
|
||||
$parent_dir = base_path().'/'.substr($dest, 0, $pos);
|
||||
if (!is_dir($parent_dir)) {
|
||||
mkdir($parent_dir, 0777, true);
|
||||
}
|
||||
}
|
||||
//symlink(__DIR__ . "/$source", base_path()."/$dest");
|
||||
copy_dir(__DIR__ . "/$source", base_path()."/$dest");
|
||||
echo "Create $dest
|
||||
";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* uninstallByRelation
|
||||
* @return void
|
||||
*/
|
||||
public static function uninstallByRelation()
|
||||
{
|
||||
foreach (static::$pathRelation as $source => $dest) {
|
||||
$path = base_path()."/$dest";
|
||||
if (!is_dir($path) && !is_file($path)) {
|
||||
continue;
|
||||
}
|
||||
echo "Remove $dest
|
||||
";
|
||||
if (is_file($path) || is_link($path)) {
|
||||
unlink($path);
|
||||
continue;
|
||||
}
|
||||
remove_dir($path);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
4
vendor/webman/cors/src/config/plugin/webman/cors/app.php
vendored
Normal file
4
vendor/webman/cors/src/config/plugin/webman/cors/app.php
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
19
vendor/webman/cors/src/config/plugin/webman/cors/middleware.php
vendored
Normal file
19
vendor/webman/cors/src/config/plugin/webman/cors/middleware.php
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return [
|
||||
'' => [
|
||||
\Webman\Cors\CORS::class
|
||||
]
|
||||
];
|
Loading…
x
Reference in New Issue
Block a user