Retrofit BASE_URL of a sub-domain on Localhost using Laragon


  • | 587 points

    I currently use Laragon in development and have a Laravel project whose URL is structured as follows

    example.test
    api.example.test
    

    I have developed the api and tested using Postman but now I need to test using the android app. In Postman, I can hit the api.example.test endpoints without any issues.

    In the Android app, I am using Retrofit but I would need to provide a BASE_URL that can be used to build other requests. I know for XAMPP, the BASE_URL looks like this

    private static final String BASE_URL = "http://my_ip_address/path/to/project/folder/relative/to/server/root".

    This ends up looking like this for a typical Laravel project

    private static final String BASE_URL = "http://192.168.0.*/example/public/api" where /api is a prefix that Laravel adds automatically to api routes.

    But since I am using Laragon, I don't even know how to write the BASE_URL because I have modified the Laravel project to route api calls to the api.example.test sub-domain.

    I have tried private static final String BASE_URL = "http://192.168.0.*/example/public/v1/" where v1 is the prefix I use to indicate the api version.

    Please help!!!


  • administrators
    | 89481 points

    @simioluwatomi : You can try another ways. There are 2 options:

    1. Use http://nip.io
    2. Use ngrok

  • | 587 points

    So after trying to share with Ngrok, all subdomain routes no longer work. I get a 404 Not Found. The requested URL was not found on this server error. I came across this and I was able to reverse it. So I guess Ngrok is out of it for me. I can't be troubleshooting an Apache 404 everytime I want to share my project.

    @leokhoa please how do I set up nip.io? I use Apache and the tutorial I have found here about that uses Nginx. I don't know what the problem is but this auto.messageapp.test.conf takes me to Laragon's index.php in my server root.

    define ROOT "C:/laragon/www/messageapp/public/"
    define SITE "messageapp.test"
    
    <VirtualHost *:80> 
        DocumentRoot "${ROOT}"
        ServerName ${SITE}
        ServerAlias *.${SITE}
        ServerAlias *.${SITE}.192.168.1.2.nip.io    
        <Directory "${ROOT}">
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    
    <VirtualHost *:443>
        DocumentRoot "${ROOT}"
        ServerName ${SITE}
        ServerAlias *.${SITE}
        <Directory "${ROOT}">
            AllowOverride All
            Require all granted
        </Directory>
    
        SSLEngine on
        SSLCertificateFile      C:/laragon/etc/ssl/messageapp.test.crt
        SSLCertificateKeyFile   C:/laragon/etc/ssl/messageapp.test.key
     
    </VirtualHost>
    

    0_1524640819504_Untitled.png


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.