1
votes

I am setting up my Laravel API on Heroku. Everything seems to be working fine, I am able to go to the site and see the Laravel public page. But when I try to access my API routes (signup, login, etc.), it returns a 404 error.

The routes work fine on my own virtual hosts that I created but once I uploaded it to Heroku, all the routes except for "/" return 404. I've checked to see if "index.php/" would work but still returns a 404.

public/htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

        RewriteCond %{REQUEST_URI} 1^public
        RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Procfile

web: vendor/bin/heroku-php-apache2 public/

routes/api.php

$api = app('Dingo\Api\Routing\Router');
$api->version("v1", function ($api) {
    $api->get("/", function () {
        return response()->json([
            'status' => 'success'
        ], 200);
    });

    $api->post("/signup", "MusicShare\Http\Controllers\AuthController@signup");
})

Heroku logs

2019-06-16T23:04:37.778061+00:00 app[web.1]: 10.35.223.16 - - [16/Jun/2019:23:04:37 +0000] "GET /index.php/routes HTTP/1.1" 200 47843 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36

My Heroku logs do not return an error. Everything shows the status code as 200 but I still get a 404 in Chrome if I try to access "/api/signup" or "/signup" or "/index.php/signup"

2

2 Answers

2
votes

if you are using apache LAMP server try this code

go to the conf file and edit this

i am using // for comminting for you

ServerAdmin webmaster@localhost DocumentRoot /var/www/html <Directory "/var/www/html"> // here you project path Options Indexes FollowSymLinks AllowOverride All // alow all permissions Require all granted </Directory>

and server restart

for this command sudo service apache2 restart

then try this command for rewrite
sudo a2enmod rewrite

and your sub routes working perfictlly

dont't forgot this command sudo a2enmod rewrite

0
votes

You have to edit the config vars --- added API_PREFIX and API_DOMAIN into the Heroku settings for my site.