traccar with laravel api as backend and vue js as forntend

mohamed_fadol4 years ago

thanks for good system traccar :)
i hope get more information
how custom traccar api in laravel api and vue js ?
i will describe my issue

1- I install laravel api as backend on my domain.com in apatche2 in port 80 on linux server , and when run domain.com:8082 will work on original or default traccar.
: laravel config :-
2- laravel config .env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:kZRk1gwFi0Z5LS8ddMvAAygJuHIQ/Gn3FeU1GX9vwoI=
APP_DEBUG=true
APP_URL=http://domain.com:8082
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=traccar
DB_USERNAME=root
DB_PASSWORD=root
SESSION_DRIVER=cookie
SESSION_DOMAINS=domain.com  // note : the main session file  set domain value as my  => domain.com
SANCTUM_STATEFUL_DOMAINS=domain.com,domain.com:8082 // there using sanctum for auth 
SESSION_SECURE_COOKIE=false
SESSION_LIFETIME=120

3- the apatche2 file like

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerName domain.com
                ServerAdmin webmaster@domain.com
                DocumentRoot /var/www/html
        ProxyRequests off
        ProxyPass /api/api/socket ws://domain.com:8082/api/socket
        ProxyPassReverse /api/api/socket ws://domain.com:8082/api/socket
        ProxyPass /api/ http://domain.com:8082/
        ProxyPassReverse /api/ http://domain.com:8082/
        ProxyPassReverseCookiePath / /api/
        Redirect permanent /api/api/
                ProxyPass /api/socket ws://domain.com:8082/api/socket
                ProxyPassReverse /api/socket ws://domain.com:8082/api/socket
                ProxyPass / http://domain.com:8082/
                ProxyPassReverse / http://domain.com:8082/
                #SSLEngine on
                #SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
                #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
        </VirtualHost>
// this VirtualHost  for laravel with file api as name of file laravel project installation
        <VirtualHost *:80>
                ServerName domain.com
                ServerAdmin webmaster@domain.com
           DocumentRoot /var/www/html/api/public
           <Directory /var/www/html/api>
               AllowOverride All
           </Directory>
        ProxyRequests off
        ProxyPass /api/api/socket ws://domain.com:8082/api/socket
        ProxyPassReverse /api/api/socket ws://domain.com:8082/api/socket
        ProxyPass /api/ http://domain.com:8082/
        ProxyPassReverse /api/ http://domain.com:8082/
        ProxyPassReverseCookiePath / /api/
        Redirect permanent /api /api/
           ErrorLog ${APACHE_LOG_DIR}/error.log
           CustomLog ${APACHE_LOG_DIR}/access.log combined
                #SSLEngine on
                #SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
                #SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
        </VirtualHost>

</IfModule>

4- the core file config :-

    'paths' => ['api/*', 'sanctum/csrf-cookie'],
    'allowed_methods' => ['*'],
    'allowed_origins' => ['*'],
    'allowed_origins_patterns' => [],
    'allowed_headers' => ['*'],
    'exposed_headers' => [],
    'max_age' => 0,
    'supports_credentials' => true,

5- when make request from vue js with axios firstly issue csrf-cookie i got it ,
but when redirect to api route /users by baseUrl => http://domain.com/api for insert user to database i got email but there is no password or hashedpassword ,

plze help by good idea or toturial
or what is wrong there in configration
thanks t, h

Victor Butler4 years ago

Hey man, did you manage to get this working? I'd like to help if you wish to collaborate!