1
0
Fork 0
mirror of synced 2024-06-29 11:40:45 +12:00
appwrite/app/controllers/shared/web.php

57 lines
2.1 KiB
PHP
Raw Normal View History

2019-05-09 18:54:39 +12:00
<?php
2020-06-29 05:31:21 +12:00
use Utopia\App;
2020-07-15 06:55:44 +12:00
use Utopia\Config\Config;
2019-05-09 18:54:39 +12:00
2020-06-30 23:09:28 +12:00
App::init(function ($utopia, $request, $response, $layout) {
/** @var Utopia\App $utopia */
/** @var Utopia\Swoole\Request $request */
2020-10-30 02:50:49 +13:00
/** @var Appwrite\Utopia\Response $response */
2020-06-30 23:09:28 +12:00
/** @var Utopia\View $layout */
2019-05-09 18:54:39 +12:00
2020-06-25 08:26:34 +12:00
/* AJAX check */
if (!empty($request->getQuery('version', ''))) {
$layout->setPath(__DIR__ . '/../../views/layouts/empty.phtml');
2020-06-25 08:26:34 +12:00
}
$port = $request->getPort();
$protocol = $request->getProtocol();
$domain = $request->getHostname();
2020-06-25 08:26:34 +12:00
$layout
->setParam('title', APP_NAME)
->setParam('protocol', $protocol)
->setParam('domain', $domain)
->setParam('endpoint', $protocol . '://' . $domain . ($port != 80 && $port != 443 ? ':' . $port : ''))
2020-06-29 08:45:36 +12:00
->setParam('home', App::getEnv('_APP_HOME'))
->setParam('setup', App::getEnv('_APP_SETUP'))
2020-06-25 08:26:34 +12:00
->setParam('class', 'unknown')
->setParam('icon', '/images/favicon.png')
->setParam('roles', [
['type' => 'owner', 'label' => 'Owner'],
['type' => 'developer', 'label' => 'Developer'],
['type' => 'admin', 'label' => 'Admin'],
])
2021-04-21 23:02:54 +12:00
->setParam('runtimes', Config::getParam('runtimes'))
2020-07-15 06:55:44 +12:00
->setParam('mode', App::getMode())
2020-06-25 08:26:34 +12:00
;
2019-05-09 18:54:39 +12:00
$time = (60 * 60 * 24 * 45); // 45 days cache
$response
->addHeader('Cache-Control', 'public, max-age=' . $time)
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time) . ' GMT') // 45 days cache
->addHeader('X-Frame-Options', 'SAMEORIGIN') // Avoid console and homepage from showing in iframes
->addHeader('X-XSS-Protection', '1; mode=block; report=/v1/xss?url=' . \urlencode($request->getURI()))
->addHeader('X-UA-Compatible', 'IE=Edge') // Deny IE browsers from going into quirks mode
;
2019-05-09 18:54:39 +12:00
$route = $utopia->match($request);
$scope = $route->getLabel('scope', '');
$layout
2020-06-30 23:09:28 +12:00
->setParam('version', App::getEnv('_APP_VERSION', 'UNKNOWN'))
2020-06-30 09:43:34 +12:00
->setParam('isDev', App::isDevelopment())
2019-05-09 18:54:39 +12:00
->setParam('class', $scope)
;
2020-06-30 23:09:28 +12:00
}, ['utopia', 'request', 'response', 'layout'], 'web');