Skip to content

Domains don't work with (custom) ports #110

@SuddenDev

Description

@SuddenDev

Wayfinder Version

0.1.12

Laravel Version

11.45.2

PHP Version

8.2.19

Description

I have an inertia application that runs on port :8001 with muliple entry points (e.g. a public fontend and an admin area). Both are on the same port but use different domains. I'm using wayfinder with the actions / controller files.

The issue I'm experiencing is that ports are not in the generated urls. This does not seem to be a problem when I'm just having GET requests and am on the same domain. But when...

  • ... linking from one domain to the other (e.g. a preview button in the admin area that links to the "frontend" preview)
  • ... having an async DELETE / POST etc. request

the url is set without the respective port and therefore breaks the routing.

The definition looks then something like this, even though I need the port in order for it to work.

destroy.definition = {
    methods: ["delete"],
    url: '//backend.my-app.test/experts/{id}',
} satisfies RouteDefinition<["delete"]>

I'm sure that once I have everything running on port 443 it's fine, but I think it would be good if it would work with custom ports. Or am i missing a setting?

Steps To Reproduce

A Laravel Inertia app with mutliple domains configured.

My web.php route with the backend routes looks something like this (simplified):

Route::domain(config('domains.backend'))
    ->middleware('auth')
    ->group(function () {

        // Expert
        Route::post('/experts/{id?}', [ExpertController::class, 'store'])->name('backend.experts.store');
        Route::delete('/experts/{id}', [ExpertController::class, 'destroy'])->name('backend.experts.destroy');

    });

and inside my HandleInertiaRequests.php

// .........

public function rootView(Request $request): string
    {
        $domainToView = [
            config('domains.backend') => 'backend', // Backend root view
            config('domains.frontend') => 'frontend', // Frontend root view
        ];

        // Get the current domain
        $currentDomain = $request->getHost();

        // Return the appropriate view or a default
        return $domainToView[$currentDomain] ?? 'fallback';
    }

// .....

The config function looks like this. Sorry if this is a little convoluted, but I'm still a little new to laravel.

function config() {
    return [
        // ......

        'domains' => [
            'frontend' => env('FRONTEND_DOMAIN', 'my-app.de'),
            'backend' => env('BACKEND_DOMAIN', 'backend.my-app.de'),
        ],
    ];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions