Skip to content

Instantly share code, notes, and snippets.

@Caffe1neAdd1ct
Last active March 16, 2016 14:28
Show Gist options
  • Save Caffe1neAdd1ct/8d6e346c09d3d9861981 to your computer and use it in GitHub Desktop.
Save Caffe1neAdd1ct/8d6e346c09d3d9861981 to your computer and use it in GitHub Desktop.
Router for Drupal 8 when using PHP InBuilt Webserver in Development
<?php
$file = pathinfo($_SERVER["SCRIPT_FILENAME"]);
$mimeTypes = [
'css' => 'text/css',
'js' => 'application/javascript',
'jpg' => 'image/jpg',
'png' => 'image/png',
'map' => 'application/json',
'svg' => 'image/svg+xml'
];
if(array_key_exists($file['extension'], $mimeTypes)) {
$path = $_SERVER["DOCUMENT_ROOT"] . $_SERVER['REQUEST_URI'];
if (is_file($_SERVER["SCRIPT_FILENAME"])) {
header("Content-Type: {$mimeTypes[$file['extension']]}");
readfile($_SERVER["SCRIPT_FILENAME"]);
exit;
}
} else {
require 'index.php';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment