laravel / horizon

Dashboard and code-driven configuration for Laravel queues.
https://laravel.com/docs/horizon
MIT License
3.87k stars 657 forks source link

Custom `uri` breaks Vue routes #245

Closed alanwillms closed 5 years ago

alanwillms commented 6 years ago

I am able to change Horizon routes:

https://github.com/laravel/horizon/blob/1f928128822a13289ae5a85b2224583837537a18/src/HorizonServiceProvider.php#L52

But the Vue application expects a fixed /horizon base path:

https://github.com/laravel/horizon/blob/1.0/resources/assets/js/router.js#L8

An ugly fix is to:

Related PR: #223

thierry2015 commented 6 years ago

Here is a temporary workaround: manually compile JS files and edit Vue and axios constructor to force custom configuration. Example from (laravel-5.7-project)/resources/js/horizon.js

import Vue from 'vue';
import VueRouter from 'vue-router';
import axios from 'axios';
import _ from 'lodash';

// Manually edit the horizon prefix
// Only prefix since the horizon URL is hardcoded in Vue components $http calls
const HORIZON_PREFIX = '/admin';

// Force router base URL in a vue instance that is using a router
const vueInit = Vue.prototype._init;
Vue.prototype._init = function(options = {}, ...args) {
    if (options.router) {
        options.router = new VueRouter(_.merge(options.router.options, {
            base: `${HORIZON_PREFIX}/horizon`
        }));
    }

    return vueInit.bind(this)(options, ...args);
};

// Force Axios to use use the horizon prefix in every relative call
const axiosCreate = axios.create;
axios.create = function(config = {}, ...args) {
    config.baseURL = `${HORIZON_PREFIX}/`;

    return axiosCreate.bind(this)(config, ...args);
};

// Import Laravel Horizon original JS file.
// Overwrite /public/vendor/horizon/js/app.js with the current file from Mix configuration file)
require('./../../vendor/laravel/horizon/resources/assets/js/app');
mapb1990 commented 6 years ago

+1

erayaydin commented 6 years ago

There should be workaround for this, other way config('horizon.uri') is unnecessary, so :+1:

loic-lopez commented 6 years ago

Hello,

How to rebuild laravel horizon assets from the main project? Thanks for reply.

thierry2015 commented 6 years ago

This file will be compiled by Mix and the output file will overwrite the vendor file: mix.js('resources/js/horizon.js', 'public/vendor/horizon/js/app.js'); To successfully compile Horizon, you will need those dependencies to be added to your package.json

loic-lopez commented 6 years ago

Thanks @thierry2015

driesvints commented 5 years ago

Since this was removed from the current release I'm going to close this. We still have plans to implement this eventually.