Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

obs's avatar
Level 3

Spark local development - wrong path in JS 404 error

I'm currently developing an webapp with Spark and have run into a problem I don't know how to fix. When I enter the register page I see a 404 error in the console "GET XHR http://localhost/geocode/country"

When I submit the form, it fails and the console shows more 404s: "POST XHR http://localhost/register"

The paths are wrong since they should point to a subfolder. I've set the APP_URL in the .env to the subfolder at localhost but the requests which lead to the 404s are made from JS files. How can I get the JS files to use the APP_URL as well? I haven't found the files yet which make these calls but I don't want to hardcode the URL anyway since it's going to change.

Thanks for your help in advance Oliver

0 likes
10 replies
EventFellows's avatar

This is where spark tries to figure out your country based on your IP and obviously this does not work for a localhost IP address.

But nevertheless is should not return an error but fall back to the default.

The url is called from here but it normally should have a default to country: US: vendor\laravel\spark\resources\assets\js\auth\register-stripe.js in the guessCountry() method.

Have you run gulp/ webpack without any errors? On my system in also works on localhost without errors.

obs's avatar
Level 3

Yes, webpack runs without errors.

But this error is not specific to the geocode - the problem is, that it calls the wrong APP URL. It just uses the server root for the URL.

EventFellows's avatar

Stupid question, I know: have you configured the url in config/app.php and can you confirm it works?

Do you also have the same issue on non-js pages?

obs's avatar
Level 3

No, I have set the APP_URL in the .env. I tried it with changing it in the config/app.php as well, but doesn't make any difference.

All the other urls I create with {{ url() }} for example are working fine.

jlucia's avatar

What is your folder structure? Depending on the complexity you may need to wrap most url's in {{ url('/') }} or even have a script variable like below in your layouts app file.

    <script>
        var App = {
            url: "{{ url('/') }}"
        };
    </script>

Then in your Vue components you can prepend the axios.get calls with App.url to look something like axios.get(App.url + '/my/spark/route'). I have seen some folks do tricks with .htaccess but I have not tried that myself. I just find wrapping the url as a basic behavior guarantees no worries later. Doing this in Spark may break future updates though, so hopefully there is a trick that I am not aware of.

EventFellows's avatar

No sure if that solves it, but I would probably try to clear all caches, like config, route, etc just to be sure that this does not cause the trouble.

obs's avatar
Level 3

@jlucia I'm pretty sure this would solve the issue, but as you said - future updates may override my customization again. I guess most people just don't have their installation in a subfolder so they don't encounter this problem, right?

@EventFellows what more would I have to do than dump-autoload?

jlucia's avatar

You could try a symlink of the subfolder to the public folder? Are you on a standard Linux?

ln -s /var/www/your-spark-master/public /var/www/html/your-spark-subfolder
EventFellows's avatar
  • php artisan config:clear
  • php artisan route:clear
  • php artisan cache:clear

that is what I would do just to be sure that is not causing it.

obs's avatar
Level 3

@EventFellows Thanks for that, but it didn't solve that.

@jlucia a symlink seems to be a suitable workaround, thank you

Please or to participate in this conversation.