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

feat: add --host option to spark routes #7213

Merged
merged 3 commits into from
Feb 5, 2023

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Feb 2, 2023

Description

  • add option to specify host in the request URL
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -31,6 +31,9 @@ $routes->set404Override();
 // route since we don't have to scan directories.
 $routes->get('/', 'Home::index');
 
+$routes->get('/', 'Account::index', ['hostname' => 'account.example.com']);
+$routes->get('/', 'Media::index', ['subdomain' => 'media']);
+
 /*
  * --------------------------------------------------------------------
  * Additional Routing
$ php spark routes

CodeIgniter v4.3.1 Command Line Tool - Server Time: 2023-02-02 05:25:26 UTC+00:00

+--------+-------+------+------------------------------+----------------+---------------+
| Method | Route | Name | Handler                      | Before Filters | After Filters |
+--------+-------+------+------------------------------+----------------+---------------+
| GET    | /     | »    | \App\Controllers\Home::index |                | toolbar       |
+--------+-------+------+------------------------------+----------------+---------------+
$ php spark routes --host account.example.com

CodeIgniter v4.3.1 Command Line Tool - Server Time: 2023-02-02 05:25:31 UTC+00:00

Host: account.example.com
+--------+-------+------+---------------------------------+----------------+---------------+
| Method | Route | Name | Handler                         | Before Filters | After Filters |
+--------+-------+------+---------------------------------+----------------+---------------+
| GET    | /     | »    | \App\Controllers\Account::index |                | toolbar       |
+--------+-------+------+---------------------------------+----------------+---------------+
$ php spark routes --host media.example.com

CodeIgniter v4.3.1 Command Line Tool - Server Time: 2023-02-02 05:25:34 UTC+00:00

Host: media.example.com
+--------+-------+------+-------------------------------+----------------+---------------+
| Method | Route | Name | Handler                       | Before Filters | After Filters |
+--------+-------+------+-------------------------------+----------------+---------------+
| GET    | /     | »    | \App\Controllers\Media::index |                | toolbar       |
+--------+-------+------+-------------------------------+----------------+---------------+

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added enhancement PRs that improve existing functionalities 4.4 labels Feb 2, 2023
@datamweb
Copy link
Contributor

datamweb commented Feb 3, 2023

@kenjis my routes:

$routes->get('/', 'Home::index');

$routes->get('/', 'Account::index', ['hostname' => 'account.example.com']);

$routes->get('/b1', 'Home::bPage', ['hostname' => 'blog.example.com']);
$routes->get('/a2', 'Home::aPage', ['hostname' => 'blog.example.com']);

$routes->get('login', 'Login::postIndex');
$routes->post('login', 'Login::postIndex');

result :

C:\Users\ppars\OneDrive\Desktop\CodeIgniter4-4.4>php spark routes --host account.example.com

CodeIgniter v4.3.1 Command Line Tool - Server Time: 2023-02-03 15:05:56 UTC+00:00

Host: account.example.com
+--------+-------+------+-----------------------------------+----------------+---------------+
| Method | Route | Name | Handler                           | Before Filters | After Filters |
+--------+-------+------+-----------------------------------+----------------+---------------+
| GET    | /     | »    | \App\Controllers\Account::index   |                | toolbar       |
| GET    | login | »    | \App\Controllers\Login::postIndex |                | toolbar       |
| POST   | login | »    | \App\Controllers\Login::postIndex |                | toolbar       |
+--------+-------+------+-----------------------------------+----------------+---------------+

In that case I expect the result to be as follows:

C:\Users\ppars\OneDrive\Desktop\CodeIgniter4-4.4>php spark routes --host account.example.com

CodeIgniter v4.3.1 Command Line Tool - Server Time: 2023-02-03 15:10:56 UTC+00:00

Host: account.example.com
+--------+-------+------+---------------------------------+----------------+---------------+
| Method | Route | Name | Handler                         | Before Filters | After Filters |
+--------+-------+------+---------------------------------+----------------+---------------+
| GET    | /     | »    | \App\Controllers\Account::index |                | toolbar       |
+--------+-------+------+---------------------------------+----------------+---------------+

@datamweb
Copy link
Contributor

datamweb commented Feb 3, 2023

And my routes:

$routes->get('/', 'Home::index');

$routes->get('/', 'Account::index', ['hostname' => 'account.example.com']);

$routes->get('/b1', 'Home::bPage', ['hostname' => 'blog.example.com']);
$routes->get('/a2', 'Home::aPage', ['hostname' => 'blog.example.com']);

result :

C:\Users\ppars\OneDrive\Desktop\CodeIgniter4-4.4>php spark routes --host blog.example.com

CodeIgniter v4.3.1 Command Line Tool - Server Time: 2023-02-03 15:40:15 UTC+00:00

Host: blog.example.com
+--------+-------+------+------------------------------+----------------+---------------+
| Method | Route | Name | Handler                      | Before Filters | After Filters |
+--------+-------+------+------------------------------+----------------+---------------+
| GET    | /     | »    | \App\Controllers\Home::index |                | toolbar       |
| GET    | b1    | »    | \App\Controllers\Home::bPage |                | toolbar       |
| GET    | a2    | »    | \App\Controllers\Home::aPage |                | toolbar       |
+--------+-------+------+------------------------------+----------------+---------------+

In that case I expect the result to be as follows:

C:\Users\ppars\OneDrive\Desktop\CodeIgniter4-4.4>php spark routes --host blog.example.com

CodeIgniter v4.3.1 Command Line Tool - Server Time: 2023-02-03 15:41:08 UTC+00:00

Host: blog.example.com
+--------+-------+------+------------------------------+----------------+---------------+
| Method | Route | Name | Handler                      | Before Filters | After Filters |
+--------+-------+------+------------------------------+----------------+---------------+
| GET    | b1    | »    | \App\Controllers\Home::bPage |                | toolbar       |
| GET    | a2    | »    | \App\Controllers\Home::aPage |                | toolbar       |
+--------+-------+------+------------------------------+----------------+---------------+

It seems that this PR needs changes.

@michalsn
Copy link
Member

michalsn commented Feb 3, 2023

@datamweb This command should list all the routes that are available for the specified hostname.

  • You can access account.example.com/login.
  • The same will be if you set host to blog.example.com - you will see the / and login routes because you can access blog.example.com/login.

@kenjis
Copy link
Member Author

kenjis commented Feb 3, 2023

Yes, this command shows all routes that are available for the specified hostname.

@datamweb
Copy link
Contributor

datamweb commented Feb 4, 2023

Okay, I get it, my take on this PR was wrong.
Thanks all.

@kenjis kenjis merged commit 0b989f1 into codeigniter4:4.4 Feb 5, 2023
@kenjis kenjis deleted the feat-spark-routes-host branch February 5, 2023 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.4 enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants