Compare commits
No commits in common. "f4629e790222a8a20f7e4d3a53e6568d068600aa" and "c83c892f53dd20504a29140c72d1ff997ecfac11" have entirely different histories.
f4629e7902
...
c83c892f53
|
@ -6,5 +6,4 @@
|
||||||
single-url="{{__SELF__.settings.singleUrl}}"
|
single-url="{{__SELF__.settings.singleUrl}}"
|
||||||
register-url="{{__SELF__.settings.registerUrl}}"
|
register-url="{{__SELF__.settings.registerUrl}}"
|
||||||
config-var-name="adrema_event_config"
|
config-var-name="adrema_event_config"
|
||||||
form-id="{{__SELF__.event.id }}"
|
|
||||||
></event-form>
|
></event-form>
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
use Silva\Adrema\Support\Proxy;
|
use Silva\Adrema\Support\Proxy;
|
||||||
|
|
||||||
Route::get('/adrema-api/{route}', fn (string $route) => Response::json(app(Proxy::class)->run($route, 'get')))
|
Route::get(
|
||||||
->where('route', '[a-zA-Z0-9\-/]+')->middleware('api');
|
'/adrema-api/{route}',
|
||||||
Route::post('/adrema-api/{route}', fn (string $route) => app(Proxy::class)->submit($route))
|
fn (string $route) => Response::json(app(Proxy::class)->run($route))
|
||||||
|
)
|
||||||
->where('route', '[a-zA-Z0-9\-/]+')->middleware('api');
|
->where('route', '[a-zA-Z0-9\-/]+')->middleware('api');
|
||||||
|
|
|
@ -4,13 +4,15 @@ namespace Silva\Adrema\Support;
|
||||||
|
|
||||||
use Silva\Adrema\Models\Settings;
|
use Silva\Adrema\Models\Settings;
|
||||||
use Http;
|
use Http;
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
|
|
||||||
class Proxy
|
class Proxy
|
||||||
{
|
{
|
||||||
public function run(string $url): ?array
|
public function run(string $url): ?array
|
||||||
{
|
{
|
||||||
$response = Http::acceptJson()->get($this->url($url));
|
$url = str($url)->start('/');
|
||||||
|
|
||||||
|
$baseUrl = Settings::get('base_url');
|
||||||
|
$response = Http::get($baseUrl . $url);
|
||||||
|
|
||||||
if (!$response->ok()) {
|
if (!$response->ok()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -18,16 +20,4 @@ class Proxy
|
||||||
|
|
||||||
return $response->json();
|
return $response->json();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function submit(string $url): JsonResponse
|
|
||||||
{
|
|
||||||
$response = Http::acceptJson()->post($this->url($url), request()->input());
|
|
||||||
|
|
||||||
return response()->json($response->json(), $response->status());
|
|
||||||
}
|
|
||||||
|
|
||||||
private function url(string $internal): string
|
|
||||||
{
|
|
||||||
return Settings::get('base_url') . str($internal)->start('/');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue