Newb 4 You BB
Newb 4 You BB

Reputation: 1355

Laravel 8 API Subdomain Unreachable

I am trying to use domain() instead of prefix() for my API's endpoint. Im not able to reach this endpoint

ENV

API_DOMAIN=api.rest-api.test

RoutServiceProvider.php

        Route::domain(env('API_DOMAIN'))
            ->middleware('api')
            ->namespace($this->namespace)
            ->group(base_path('routes/api.php'));

API.php

Route::get('/person', function(){
    $person = [
        'first-name' => 'Bob',
        'last-name' => 'Tables'
    ];

    return $person;
});

Postman Error

Error: getaddrinfo ENOTFOUND api.rest-api.test

EDIT : I neglected to mention that this worked properly with the default prefix() option.

Upvotes: 1

Views: 319

Answers (1)

Newb 4 You BB
Newb 4 You BB

Reputation: 1355

The tutorial I was watching was using Valet (Mac only) so their domains were mapped automatically. For Windows users, you will need to manually add domains to your etc/hosts file.

Upvotes: 1

Related Questions