2017-01-19 20:39:01 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace OCA\Passman\Middleware;
|
|
|
|
|
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
|
|
use OCP\AppFramework\Http\Response;
|
2023-06-16 02:40:05 +08:00
|
|
|
use OCP\AppFramework\Middleware;
|
2017-01-19 20:39:01 +08:00
|
|
|
use OCP\IRequest;
|
|
|
|
|
|
|
|
class APIMiddleware extends Middleware {
|
|
|
|
|
2023-07-05 19:02:29 +08:00
|
|
|
public function __construct(
|
|
|
|
private IRequest $request,
|
|
|
|
) {
|
2017-01-19 20:39:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function afterController($controller, $methodName, Response $response) {
|
|
|
|
if($response instanceof JSONResponse){
|
2017-01-19 20:58:34 +08:00
|
|
|
if(isset($this->request->server['HTTP_ORIGIN'])) {
|
|
|
|
$response->addHeader('Access-Control-Allow-Origin', $this->request->server['HTTP_ORIGIN']);
|
2023-06-16 02:40:05 +08:00
|
|
|
} else {
|
|
|
|
$response->addHeader('Access-Control-Allow-Origin', '*');
|
|
|
|
}
|
2017-01-19 20:39:01 +08:00
|
|
|
}
|
|
|
|
return parent::afterController($controller, $methodName, $response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|