$app->pipe(Middleware::TrailingSlash(false)->redirect(301)); $app->pipe(Middleware::FormatNegotiator()); // required for Expires, Minify //$app->pipe(Middleware::Expires()); //$app->pipe(Middleware::Minify()); $app->pipe(Middleware::BlockSpam()); //$app->pipe(Middleware::PhpSession()->name('DetectorSessionId')); //$app->pipe(Middleware::Geolocate()->saveInSession(true)); //$app->pipe(Middleware::Cache($pool)); $app->pipe(Middleware::responseTime()); $app->pipeRoutingMiddleware(); $app->pipeDispatchMiddleware(); $cache = new File(array(File::DIR => 'cache/')); $app->get('/js/features.js', function (RequestInterface $request, ResponseInterface $response, callable $next) use($errorLog, $cache) { $response->withAddedHeader('content-type', 'application/x-javascript'); $response->getBody()->write(Modernizr::buildJs()); $detector = new Detector($cache, $errorLog); $cookieID = $detector->getCookieId($_SERVER); $response->getBody()->write(Modernizr::buildConvertJs($cookieID, '', false)); return $response; }); $app->get('/', function (RequestInterface $request, ResponseInterface $response, callable $next) use($errorLog, $cache) { $detector = new Detector($cache, $errorLog); // if this is a request from features.js.php don't run the build function $ua = $detector->build($_SERVER); /* if (null === $ua) { $html = '<html><head><script type="text/javascript">'; $html .= Modernizr::buildJs(); $html .= Modernizr::buildConvertJs($detector->getCookieId($_SERVER), '', true);
<?php chdir(dirname(dirname(__DIR__))); $autoloadPaths = array('vendor/autoload.php', '../../autoload.php'); $foundVendorAutoload = false; foreach ($autoloadPaths as $path) { if (file_exists($path)) { require $path; $foundVendorAutoload = true; break; } } if (!$foundVendorAutoload) { throw new Exception('Could not find autoload path in any of the searched locations'); } $p = true; // turn off the build function use Detector\Detector; use ModernizrServer\Modernizr; use Monolog\Handler\StreamHandler; use Monolog\Logger; use WurflCache\Adapter\File; header('content-type: application/x-javascript', true); $logger = new Logger('detector'); $logger->pushHandler(new StreamHandler('log/error.log', Logger::NOTICE)); $cache = new File(array(File::DIR => 'cache/')); $detector = new Detector($cache, $logger); $cookieID = $detector->getCookieId($_SERVER); print Modernizr::buildJs(); print Modernizr::buildConvertJs($cookieID, '', false);