-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMediaWikiHostsController.php
More file actions
37 lines (33 loc) · 1.34 KB
/
MediaWikiHostsController.php
File metadata and controls
37 lines (33 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace App\Http\Controllers\Backend;
use App\Http\Controllers\Controller;
use App\Services\MediaWikiHostResolver;
use App\Services\UnknownDBVersionException;
use App\Services\UnknownWikiDomainException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class MediaWikiHostsController extends Controller {
public function getWikiHostsForDomain(Request $request): JsonResponse {
$mediawikiHostResolver = new MediaWikiHostResolver;
$domain = $request->query('domain');
try {
$hosts = $mediawikiHostResolver->getHostsForDomain($domain);
} catch (UnknownWikiDomainException) {
return response()->json(['error' => 'Domain not found.'], 404);
} catch (UnknownDBVersionException) {
return response()->json(['error' => 'Unknown database version.'], 500);
}
return response()
->json([
'domain' => $domain,
'backend-host' => $hosts['backend'],
'web-host' => $hosts['web'],
'api-host' => $hosts['api'],
'alpha-host' => $hosts['alpha'],
])
->header('x-backend-host', $hosts['backend'])
->header('x-web-host', $hosts['web'])
->header('x-api-host', $hosts['api'])
->header('x-alpha-host', $hosts['alpha']);
}
}