kerigard/laravel-mix-token

This package is abandoned and no longer maintained. No replacement package was suggested.

Tracking changes in files generated with Laravel Mix

v1.0.3 2022-08-06 15:43 UTC

This package is auto-updated.

Last update: 2023-03-06 17:09:09 UTC


README

Build Status Total Downloads Latest Stable Version License

Tracking changes in files created with Laravel Mix for SPA applications.

Installation

Via Composer

composer require kerigard/laravel-mix-token

Usage

You should add middleware to your api middleware group within your application's app/Http/Kernel.php file:

'api' => [
    \Kerigard\MixToken\SetMixHeader::class,
    'throttle:api',
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
],

Add token in an HTML meta tag:

<meta name="mix-token" content="{{ mix_token() }}">

To find out if there are changes, you need to add the X-Requested-With header to all requests to the server and check if there is a difference between the token in the meta tag and the X-Mix-Token header when answering.

import axios from 'axios'

const mixToken = document.head.querySelector('meta[name=mix-token]').content
const instance = axios.create({
  headers: { 'X-Requested-With': 'XMLHttpRequest' }
})

instance.interceptors.response.use(
  (response) => {
    if (response.headers['x-mix-token'] !== undefined && response.headers['x-mix-token'] != mixToken) {
      console.log('Mix manifest has been changed. Ask the user to refresh the page')
    }

    return response
  },
)

Change log

Please see the CHANGELOG for more information on what has changed recently.

License

MIT. Please see the LICENSE FILE for more information.