question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uri without https

See original GitHub issue

Description

I use @routes of ziggy with Laravel and deploy it to Heroku as host. The problem is @routes render in HTML the protocol of uri is http. I want it to be https or change depend on current URL, but even I set up APP_URL it doesn’t change.

I am not sure it only happen on Heroku or not. Thanks

Expected behavior

route() helper get correct uri. For example: https://demo.herokuapp.com shouldn’t get http://demo.herokuapp.com which will get Error: Network Error.

Environment

  • Laravel version: 8.29
  • Ziggy version: 1.0.5

Related routes:

All

Ziggy.routes:

{
    "login": {
        "uri": "login",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "logout": {
        "uri": "logout",
        "methods": [
            "POST"
        ]
    },
    "password.request": {
        "uri": "forgot-password",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "password.reset": {
        "uri": "reset-password/{token}",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "password.email": {
        "uri": "forgot-password",
        "methods": [
            "POST"
        ]
    },
    "password.update": {
        "uri": "reset-password",
        "methods": [
            "POST"
        ]
    },
    "register": {
        "uri": "register",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "verification.notice": {
        "uri": "email/verify",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "verification.verify": {
        "uri": "email/verify/{id}/{hash}",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "verification.send": {
        "uri": "email/verification-notification",
        "methods": [
            "POST"
        ]
    },
    "user-profile-information.update": {
        "uri": "user/profile-information",
        "methods": [
            "PUT"
        ]
    },
    "user-password.update": {
        "uri": "user/password",
        "methods": [
            "PUT"
        ]
    },
    "password.confirm": {
        "uri": "user/confirm-password",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "password.confirmation": {
        "uri": "user/confirmed-password-status",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "two-factor.login": {
        "uri": "two-factor-challenge",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "landing": {
        "uri": "/",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "oauth.login": {
        "uri": "login/{provider}",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "oauth.callback": {
        "uri": "login/{provider}/callback",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "projects.index": {
        "uri": "projects",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "projects.create": {
        "uri": "projects/create",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "profile.show": {
        "uri": "user/profile/{component?}",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "other-browser-sessions.destroy": {
        "uri": "user/other-browser-sessions",
        "methods": [
            "DELETE"
        ]
    },
    "current-user.destroy": {
        "uri": "user",
        "methods": [
            "DELETE"
        ]
    },
    "teams.index": {
        "uri": "teams",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "teams.create": {
        "uri": "teams/create",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "teams.store": {
        "uri": "teams",
        "methods": [
            "POST"
        ]
    },
    "teams.show": {
        "uri": "teams/{team}",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "teams.edit": {
        "uri": "teams/{team}/edit",
        "methods": [
            "GET",
            "HEAD"
        ]
    },
    "teams.update": {
        "uri": "teams/{team}",
        "methods": [
            "PUT"
        ]
    },
    "teams.destroy": {
        "uri": "teams/{team}",
        "methods": [
            "DELETE"
        ]
    },
    "current-team.update": {
        "uri": "current-team",
        "methods": [
            "PUT"
        ]
    },
    "team-members.store": {
        "uri": "teams/{team}/members",
        "methods": [
            "POST"
        ]
    },
    "team-members.update": {
        "uri": "teams/{team}/members/{user}",
        "methods": [
            "PUT"
        ]
    },
    "team-members.destroy": {
        "uri": "teams/{team}/members/{user}",
        "methods": [
            "DELETE"
        ]
    },
    "team-invitations.accept": {
        "uri": "team-invitations/{invitation}",
        "methods": [
            "GET",
            "HEAD"
        ],
        "bindings": {
            "invitation": "id"
        }
    },
    "team-invitations.destroy": {
        "uri": "team-invitations/{invitation}",
        "methods": [
            "DELETE"
        ],
        "bindings": {
            "invitation": "id"
        }
    },
    "user-pinned-teams.store": {
        "uri": "user-pinned-teams/{team}",
        "methods": [
            "POST"
        ],
        "bindings": {
            "team": "id"
        }
    },
    "user-pinned-teams.destroy": {
        "uri": "user-pinned-teams/{team}",
        "methods": [
            "DELETE"
        ],
        "bindings": {
            "team": "id"
        }
    }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

7reactions
AlexR1712commented, Apr 6, 2021

@cesg yes, if you are having this issue when you are deploying your application via Docker in my case using Dokku You need to define all the trusted proxies in order to avoid this problem because your application is being forwarded traffic from your load balancer/reverse proxy on port 80 and does not know it should generate secure links.

So just edit the middleware App\Http\Middleware\TrustProxies

In my case, I do just add ‘*’ to trust to all proxies.

<?php

namespace App\Http\Middleware;

use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;

class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var string|array
     */
    protected $proxies = '*';

    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO;
}
5reactions
cesgcommented, Apr 6, 2021

I solved it configuring trusted proxies docs

Read more comments on GitHub >

github_iconTop Results From Across the Web

URL without "http|https" - Stack Overflow
I just learned from a colleague that omitting the "http | https" part of a URL in a link will make that URL...
Read more >
Will URI without https be as secure?
But mostly it depends upon your browser security .Check if “always use secure connection” is on (which is on by default on chrome...
Read more >
Open URL does not open URL without https or www?
I am passing URL to Open URL and the logs show that, but it does nothing. When I use it to open the...
Read more >
The components of a URL - IBM
A URL (Uniform Resource Locator) is a specific type of URI (Universal Resource ... It can be HTTP (without SSL) or HTTPS (with...
Read more >
Uri Class (System) | Microsoft Learn
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found