Skip to content
New issue

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

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

Already on GitHub? # to your account

Fixing issue #319 #320

Merged
merged 14 commits into from
Sep 29, 2018
Merged

Fixing issue #319 #320

merged 14 commits into from
Sep 29, 2018

Conversation

emulienfou
Copy link
Contributor

Fixing issue #319.
Based from the PR #185 by @chandon this fix has been ported to Symfony 4 and tested by myself!

@emulienfou
Copy link
Contributor Author

@stof what do you think about this PR?

@tobias-93
Copy link
Collaborator

As you can see in the tests, you completely change the behavior of the router in some cases. Please make sure you only add new functionality without changing the current behavior. Could you provide some tests with a changed port as well?

@emulienfou
Copy link
Contributor Author

Port extension test added, all tests are up and running!

@dmaicher
Copy link
Contributor

dmaicher commented Jul 30, 2018

I just tested this on my app where I use a non-standard port for end-to-end tests and it works nicely 👍

Any chance this can be merged? I hope this will not end the same way as #185.

@emulienfou
Copy link
Contributor Author

@stof @tobias-93

@dmaicher
Copy link
Contributor

dmaicher commented Jul 30, 2018

@emulienfou actually I made a mistake in my previous tests and it was using a cached response for the route export.

I just tested it again and actually this fix does not work for me. For generated routes it does not correctly append the port for me.

Maybe its because I use multiple hosts and have host restrictions on the routes that I tested?

If I use dev-master from git@github.com:chandon/FOSJsRoutingBundle.git it works.

@emulienfou
Copy link
Contributor Author

Hi @dmaicher, just to be sure, here whats in my fos_js_routes.json file:

{  
   "base_url":"",
   "routes":{
      "projectharmony_message_new":{  
         "tokens":[  
            [  
               "text",
               "\/messages\/new"
            ]
         ],
         "defaults":[  

         ],
         "requirements":[  

         ],
         "hosttokens":[  
            [  
               "text",
               "account.harmonycms.net"
            ]
         ],
         "methods":[  

         ],
         "schemes":[  

         ]
      },
   },
   "prefix":"",
   "host":"localhost:8082",
   "portextension":":8082",
   "scheme":"http"
}

Do you have the portextension key and the port append to the host key?

Do you think port is missing in the hosttokens key?

Actually my modifications is working perfectly in my app, using FOSMessageBundle and others!!!

@dmaicher
Copy link
Contributor

@emulienfou

example:

{
  "base_url": "",
  "routes": {
    "some_route_name": {
      "tokens": [
        [
          "variable",
          "\/",
          "[^\/]++",
          "hash"
        ],
        [
          "text",
          "\/ca\/replace"
        ]
      ],
      "defaults": [],
      "requirements": [],
      "hosttokens": [
        [
          "text",
          "my-host.loc"
        ]
      ],
      "methods": [
        "GET",
        "POST"
      ],
      "schemes": []
    },
  },
  "prefix": "",
  "host": "my-host.loc:81",
  "portextension": ":81",
  "scheme": "http"
}

So now I am on http://my-host.loc:81/... and I generate the route using

Routing.generate('some_route_name', {'hash':'foo'});

Now gives me: http://my-host.loc/ca/replace/foo

With the PR #185 I get /ca/replace/foo which is relative and works with the correct port then.

@emulienfou
Copy link
Contributor Author

So weird, I got the same fix but not the same output.

In your composer.lock you are using the commit 42fd6a7234aea6782a94f5eb5328940006347150 on my fork repo?

Because I get the url, by example http://marketplace.harmonycms.net::8082/vote/1/theme when generating the route like you do!

@dmaicher
Copy link
Contributor

David Sanchez added 3 commits July 30, 2018 13:41
Append color `:` only when *host + port* are used in JS and Extractor
@emulienfou
Copy link
Contributor Author

@tobias-93 Issue fixed
@dmaicher can you do a test with your app ?

FYI: Travis fail only on PHP5.3, due to travis, not my PR, check logs

Copy link
Contributor

@dmaicher dmaicher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works now 👍

small comments on how to simplify it

@@ -104,14 +104,26 @@ public function getHost()
{
$requestContext = $this->router->getContext();

$host = $requestContext->getHost();
$host = $requestContext->getHost() .
('' === $this->getPortExtension() ? $this->getPortExtension() : ':' . $this->getPortExtension());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@emulienfou emulienfou Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove the colon : because the tests are wrong.

  • For me, portextension should only contain port number without colon.
  • In the JS test case , we need to test with portextension: ':443' instead of portextension: 443
  • And yes, I think the comment is wrong and need to be changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it called portExtension then? can be just port?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good question.
This came from the PR #185

Copy link
Contributor Author

@emulienfou emulienfou Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I can rename portExtension by port. I think, like you said, everyone will know what it is ?

@@ -263,8 +281,8 @@ class Router {
url = route.requirements["_scheme"] + "://" + (host || this.getHost()) + url;
} else if ("undefined" !== typeof route.schemes && "undefined" !== typeof route.schemes[0] && this.getScheme() !== route.schemes[0]) {
url = route.schemes[0] + "://" + (host || this.getHost()) + url;
} else if (host && this.getHost() !== host) {
url = this.getScheme() + "://" + host + url;
} else if (host && this.getHost() !== host + ('' === portextension ? '' : ':' + portextension)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of code has been changed, because I remove the colon : in the portextension variable.
Like I said before, the portextension variable should only contain an int value with the port number

@lsmith77
Copy link
Member

lsmith77 commented Aug 7, 2018

can you check if you can make the tests pass on PHP 5.6?
otherwise we might just go to PHP 7 as the minimum requirement.

@emulienfou
Copy link
Contributor Author

@lsmith77 did we deprecate PHP 5.3 too from composer.json file?

@rvmourik
Copy link

Any progress on getting this merged?

@lsmith77 lsmith77 merged commit fce90c6 into FriendsOfSymfony:master Sep 29, 2018
@lsmith77
Copy link
Member

not using the Bundle but took the “risk” of merging it since it looks good and the tests pass.

@rvmourik
Copy link

@lsmith77 Thanks, are you going to make a release so i can update my composer without pinning it to the dev-master?

@lsmith77
Copy link
Member

https://github.com/FriendsOfSymfony/FOSJsRoutingBundle/releases/tag/2.2.1

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants