Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a router to the built-in serve command #12310

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions bootstrap/router.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

// Allow the PHP development server to route requests to static files
$parts = parse_url($_SERVER['REQUEST_URI'] ?? '');
if (!empty($parts['path'])) {
if (realpath($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $parts['path'])) {
return false;
}
}

// Yii expects the SCRIPT_FILENAME to come out of the document root or the Request object
// can't find itself. So we'll fake it and make it think we're accessing the index
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'index.php';

// Run Craft as normal
include $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'index.php';
6 changes: 6 additions & 0 deletions src/console/controllers/ServeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class ServeController extends BaseServeController
*/
public $docroot = '@webroot';

/**
* @var string path or [path alias](guide:concept-aliases) to router script.
* See https://www.php.net/manual/en/features.commandline.webserver.php
*/
public $router = '@app/../bootstrap/router.php';

/**
* @inheritdoc
*/
Expand Down