Add native EzServer macOS compatibility preview
This commit is contained in:
1 parent
6b95fbb1fc
commit
9d8b2fcbb1
10 files changed
+396
-3
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
// Launch the original API front controller for the verified, database-independent routes.
|
||||
function failRequest($status, $message)
|
||||
{
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo json_encode(['error' => $message]);
|
||||
}
|
||||
|
||||
header('Cache-Control: no-store');
|
||||
$host = $_SERVER['HTTP_HOST'] ?? '';
|
||||
if (!preg_match('/\A(?:127\.0\.0\.1|localhost)(?::[0-9]{1,5})?\z/i', $host)) {
|
||||
failRequest(400, 'Use a loopback host');
|
||||
return;
|
||||
}
|
||||
if (($_SERVER['REQUEST_METHOD'] ?? '') !== 'GET') {
|
||||
header('Allow: GET');
|
||||
failRequest(405, 'Only GET is supported');
|
||||
return;
|
||||
}
|
||||
|
||||
$runtime = getenv('EZSERVER_RUNTIME');
|
||||
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
|
||||
if ($path === '/') {
|
||||
header('Content-Type: text/html; charset=utf-8');
|
||||
readfile($runtime . '/index.html');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preg_match('~\A/api(?:/index\.php)?(?:/v1/info/(?:versions|versionsbyname))?/?\z~i', $path ?? '')) {
|
||||
failRequest(404, 'Route is unavailable in the macOS preview');
|
||||
return;
|
||||
}
|
||||
|
||||
$public = $runtime . '/www/ezwebserver/src/public';
|
||||
$_SERVER['DOCUMENT_ROOT'] = $public;
|
||||
$_SERVER['SCRIPT_FILENAME'] = $public . '/api/index.php';
|
||||
$_SERVER['SCRIPT_NAME'] = '/api/index.php';
|
||||
$_SERVER['PHP_SELF'] = '/api/index.php';
|
||||
$_SERVER['CI_ENV'] = 'production';
|
||||
chdir($public . '/api');
|
||||
require $_SERVER['SCRIPT_FILENAME'];
|
||||
Reference in new issue
Block a user