Skip to content

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

Merged
kenjis merged 3 commits into
codeigniter4:4.4from
kenjis:feat-spark-routes-host
Feb 5, 2023
Merged

kenjis merged 3 commits into
codeigniter4:4.4from
kenjis:feat-spark-routes-host

Conversation

@kenjis

@kenjis kenjis commented Feb 2, 2023

Copy link
Copy Markdown
Member

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

datamweb commented Feb 3, 2023

Copy link
Copy Markdown
Contributor

@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

datamweb commented Feb 3, 2023

Copy link
Copy Markdown
Contributor

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

michalsn commented Feb 3, 2023

Copy link
Copy Markdown
Member

@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

kenjis commented Feb 3, 2023

Copy link
Copy Markdown
Member Author

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

@datamweb

datamweb commented Feb 4, 2023

Copy link
Copy Markdown
Contributor

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

enhancement PRs that improve existing functionalities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants