mirror of
https://github.com/nextcloud/passman.git
synced 2024-11-10 17:27:40 +08:00
9fd9045455
Signed-off-by: Hamid Dehnavi <hamid.dev.pro@gmail.com>
29 lines
734 B
PHP
29 lines
734 B
PHP
<?php
|
|
|
|
namespace OCA\Passman\Middleware;
|
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
use OCP\AppFramework\Http\Response;
|
|
use OCP\AppFramework\Middleware;
|
|
use OCP\IRequest;
|
|
|
|
class APIMiddleware extends Middleware {
|
|
|
|
public function __construct(
|
|
private IRequest $request,
|
|
) {
|
|
}
|
|
|
|
public function afterController($controller, $methodName, Response $response) {
|
|
if($response instanceof JSONResponse){
|
|
if(isset($this->request->server['HTTP_ORIGIN'])) {
|
|
$response->addHeader('Access-Control-Allow-Origin', $this->request->server['HTTP_ORIGIN']);
|
|
} else {
|
|
$response->addHeader('Access-Control-Allow-Origin', '*');
|
|
}
|
|
}
|
|
return parent::afterController($controller, $methodName, $response);
|
|
}
|
|
}
|
|
|
|
|