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

Dynamic API URLs stopped working with ".test" Domains in 3.4.x #2804

Closed
helllicht opened this issue Sep 4, 2020 · 6 comments
Closed

Dynamic API URLs stopped working with ".test" Domains in 3.4.x #2804

helllicht opened this issue Sep 4, 2020 · 6 comments
Labels
needs: information ❓ Requires more information to proceed

Comments

@helllicht
Copy link

helllicht commented Sep 4, 2020

Describe the bug
Up until 3.4.0 it was able to define dynamic API urls via query builder syntax in checkbox blueprint fields.
E.g. url: "{{ site.url }}/some.json"

The important part here is the site.url which would dynamically set the site's url for calling the right route.
In this example it would return a json object from a custom Kirby Route that would populate the checkbox field (see example further below)

This was working perfectly fine until updating to 3.4.0, where it stopped working.
Now, when calling the respective page in the backend, it would show the following error:
Locally: Could not resolve: your-domain.test (Domain name not found)
On Production: Invalid options format See Update 2

To Reproduce
Steps to reproduce the behavior:

  1. Create a blueprint field for a page as follows:
label: Checkboxes
type: checkboxes
options: api
columns: 2
api:
  url: "{{ site.url }}/some/route.json"
  text: "{{ item.name }}"
  value: "{{ item.id }}"
  1. Open the respective page in the panel
  2. You should see the error described above

Expected behavior
The field should list the checkbox items based on the content of the json from the route

Kirby Version
3.4.0 / 3.4.1 / 3.4.2


Update: At least for local development it seems to be be related to the .test Domain.
Switching the url to a hardcoded url: "http://localhost:3000/some/route.json" resolves the issue locally.


Update 2:
Updated the issue and description as the problems in local/prod are coincidentally and not related to each other.
The Invalid options are a result of the password protection on the live domain. That's an a different issue in general.

@afbora
Copy link
Member

afbora commented Sep 4, 2020

If there was no point I missed, I couldn't reproduce the issue on 3.4.2 🤔

Blueprint

fields:
  test:
    label: Checkboxes
    type: checkboxes
    options: api
    columns: 2
    api:
      url: "{{ site.url }}/test.json"
      text: "{{ item.text }}"
      value: "{{ item.value }}"

Config

return [
    'debug' => true,
    'routes' => [
        [
          'pattern' => 'test.json',
          'action'  => function () {
            return json_encode([
                [
                  'value'=> 'APPLE',
                  'text'=> 'Apple'
                ],
                [
                  'value'=> 'INTEL',
                  'text' => 'Intel'
                ],
                [
                  'value'=> 'MICROSOFT',
                  'text' => 'Microsoft'
                ]
            ]);
          }
        ]
      ]
];

Output

screen-capture-258-Sandbox - Mægazine-localhost

@helllicht helllicht changed the title Dynamic API URLs stopped working in 3.4.x Dynamic API URLs stopped working in 3.4.x? Sep 7, 2020
@helllicht
Copy link
Author

Update: At least for local development it might be related to the .test Domain.
Switching the url to a hardcoded url: "http://localhost:3000/some/route.json" resolves the issue locally.

@helllicht helllicht changed the title Dynamic API URLs stopped working in 3.4.x? Dynamic API URLs stopped working with ".test" Domains in 3.4.x Sep 7, 2020
@helllicht
Copy link
Author

@afbora Thanks for testing, I updated the headline and description, as it seems that the issue is related to the .test domains we're using locally (via Laravel Valet)

@afbora
Copy link
Member

afbora commented Sep 7, 2020

@helllicht Could this be a valet issue? laravel/valet#736

@bastianallgeier bastianallgeier added the needs: information ❓ Requires more information to proceed label Sep 7, 2020
@bastianallgeier
Copy link
Member

It looks to me like a host problem as well. We switched to cURL for the API calls and no longer use file_get_contents. That's why the host check is probably different.

@helllicht
Copy link
Author

@bastianallgeier @afbora Thanks for chiming in. You're absolutely right, thanks for the hint. We were able to resolve it following one of the suggestions in the issue thread. 👍

The change to cURL also explains why it stopped working after the update to 3.4.0

Unfortunately this also means that API calls on password protected servers (like staging server) won't work. But I guess that's an issue for another day :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: information ❓ Requires more information to proceed
Projects
None yet
Development

No branches or pull requests

2 participants