Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa4784c8ec | ||
|
|
cd00572702 | ||
|
|
8c042b27cf | ||
|
|
4aa046d7a7 | ||
|
|
859dcf99be | ||
|
|
2893ed0bc6 | ||
|
|
15e9fcc186 | ||
|
|
42404cc2cc | ||
|
|
b53047a28c | ||
|
|
5eff0cafe5 | ||
|
|
0e25ead520 | ||
|
|
67507d036a | ||
|
|
0ce7b51eff | ||
|
|
891c3d8ff8 | ||
|
|
e2062499ae | ||
|
|
1f4bbadab7 |
No files matched your search
@@ -14,7 +14,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Dependabot metadata
|
- name: Dependabot metadata
|
||||||
id: metadata
|
id: metadata
|
||||||
uses: dependabot/fetch-metadata@v2.3.0
|
uses: dependabot/fetch-metadata@v2.4.0
|
||||||
with:
|
with:
|
||||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
ref: ${{ github.head_ref }}
|
ref: ${{ github.head_ref }}
|
||||||
|
|
||||||
- name: Fix PHP code style issues
|
- name: Fix PHP code style issues
|
||||||
uses: aglipanci/laravel-pint-action@2.4
|
uses: aglipanci/laravel-pint-action@2.5
|
||||||
|
|
||||||
- name: Commit changes
|
- name: Commit changes
|
||||||
uses: stefanzweifel/git-auto-commit-action@v5
|
uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
|
|||||||
@@ -16,14 +16,27 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: true
|
fail-fast: true
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest]
|
os: [ubuntu-latest]
|
||||||
php: [8.4, 8.3]
|
php: [8.3, 8.4]
|
||||||
laravel: [11.*]
|
laravel: [11.*, 12.*]
|
||||||
stability: [prefer-lowest, prefer-stable]
|
stability: [prefer-lowest, prefer-stable]
|
||||||
include:
|
include:
|
||||||
- laravel: 11.*
|
- laravel: 11.*
|
||||||
|
php: 8.3
|
||||||
testbench: 9.*
|
testbench: 9.*
|
||||||
carbon: ^2.63
|
carbon: ^2.63
|
||||||
|
- laravel: 11.*
|
||||||
|
php: 8.4
|
||||||
|
testbench: 9.*
|
||||||
|
carbon: ^2.63
|
||||||
|
- laravel: 12.*
|
||||||
|
php: 8.3
|
||||||
|
testbench: 10.*
|
||||||
|
carbon: ^3.8.4
|
||||||
|
- laravel: 12.*
|
||||||
|
php: 8.4
|
||||||
|
testbench: 10.*
|
||||||
|
carbon: ^3.8.4
|
||||||
|
|
||||||
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
|
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
|
||||||
|
|
||||||
@@ -43,9 +56,18 @@ jobs:
|
|||||||
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
|
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
|
||||||
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
|
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
|
||||||
|
|
||||||
|
- name: Remove Larastan if Laravel 12
|
||||||
|
if: startsWith(matrix.laravel, '12.')
|
||||||
|
run: composer remove larastan/larastan --dev --no-update || true
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.os == 'windows-latest' && '^^^' || '' }}${{ matrix.carbon }}" --no-interaction --no-update
|
composer require \
|
||||||
|
"laravel/framework:${{ matrix.laravel }}" \
|
||||||
|
"orchestra/testbench:${{ matrix.testbench }}" \
|
||||||
|
"nesbot/carbon:${{ matrix.carbon }}" \
|
||||||
|
--no-interaction --no-update
|
||||||
|
|
||||||
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
|
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
|
||||||
|
|
||||||
- name: List Installed Dependencies
|
- name: List Installed Dependencies
|
||||||
|
|||||||
@@ -2,6 +2,28 @@
|
|||||||
|
|
||||||
All notable changes to `laravel-plausible-proxy` will be documented in this file.
|
All notable changes to `laravel-plausible-proxy` will be documented in this file.
|
||||||
|
|
||||||
|
## v1.4 - 2025-06-16
|
||||||
|
|
||||||
|
### What's Changed
|
||||||
|
|
||||||
|
* Bump aglipanci/laravel-pint-action from 2.4 to 2.5 by @dependabot in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/3
|
||||||
|
* Bump dependabot/fetch-metadata from 2.3.0 to 2.4.0 by @dependabot in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/4
|
||||||
|
* Added support for L12 by @mathiaspalmqvist in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/7
|
||||||
|
|
||||||
|
### New Contributors
|
||||||
|
|
||||||
|
* @dependabot made their first contribution in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/3
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/compare/v1.3...v1.4
|
||||||
|
|
||||||
|
## v1.3 - 2025-01-31
|
||||||
|
|
||||||
|
### What's Changed
|
||||||
|
|
||||||
|
* Remove site by @mathiaspalmqvist in https://github.com/MattitjaAB/laravel-plausible-proxy/pull/2
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/compare/v1.2...v1.3
|
||||||
|
|
||||||
## v1.2 - 2025-01-31
|
## v1.2 - 2025-01-31
|
||||||
|
|
||||||
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/compare/v1.1...v1.2
|
**Full Changelog**: https://github.com/MattitjaAB/laravel-plausible-proxy/compare/v1.1...v1.2
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
A Laravel package for proxying Plausible Analytics, improving performance.
|
A Laravel package for proxying Plausible Analytics, improving performance.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
- Laravel 11
|
- Laravel 12
|
||||||
- PHP 8.3+
|
- PHP 8.3, 8.4
|
||||||
|
|
||||||
## 🚀 Installation
|
## 🚀 Installation
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"php": "^8.3",
|
"php": "^8.3",
|
||||||
"spatie/laravel-package-tools": "^1.16",
|
"spatie/laravel-package-tools": "^1.16",
|
||||||
"illuminate/contracts": "^10.0||^11.0"
|
"illuminate/contracts": "^10.0||^11.0||^12.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"laravel/pint": "^1.14",
|
"laravel/pint": "^1.14",
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace MattitjaAB\LaravelPlausibleProxy\Database\Factories;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
|
|
||||||
/*
|
|
||||||
class ModelFactory extends Factory
|
|
||||||
{
|
|
||||||
protected $model = YourModel::class;
|
|
||||||
|
|
||||||
public function definition()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::create('laravel_plausible_proxy_table', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
|
|
||||||
// add fields
|
|
||||||
|
|
||||||
$table->timestamps();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
+1
-2
@@ -6,7 +6,6 @@ parameters:
|
|||||||
paths:
|
paths:
|
||||||
- src
|
- src
|
||||||
- config
|
- config
|
||||||
- database
|
|
||||||
tmpDir: build/phpstan
|
tmpDir: build/phpstan
|
||||||
checkOctaneCompatibility: true
|
checkOctaneCompatibility: true
|
||||||
checkModelProperties: true
|
checkModelProperties: true
|
||||||
Whitespace-only changes.
+2
-31
@@ -1,35 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use MattitjaAB\LaravelPlausibleProxy\Http\Controllers\PlausibleEventApiController;
|
||||||
|
|
||||||
Route::post('api/event', function (Request $request) {
|
Route::post('api/event', PlausibleEventApiController::class);
|
||||||
$data = json_decode($request->getContent(), true);
|
|
||||||
|
|
||||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
|
||||||
return response()->json(['error' => 'Invalid JSON format'], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
$validator = Validator::make($data, [
|
|
||||||
'n' => 'required|string',
|
|
||||||
'u' => 'required|url',
|
|
||||||
'd' => 'required|string',
|
|
||||||
'r' => 'nullable|url',
|
|
||||||
'm' => 'nullable|string',
|
|
||||||
'p' => 'nullable|array',
|
|
||||||
]);
|
|
||||||
|
|
||||||
if ($validator->fails()) {
|
|
||||||
return response()->json(['status' => 'error', 'errors' => $validator->errors()], 422);
|
|
||||||
}
|
|
||||||
|
|
||||||
$headers = collect($request->headers->all())
|
|
||||||
->mapWithKeys(fn ($value, $key) => [$key => is_array($value) ? implode(', ', $value) : $value])
|
|
||||||
->all();
|
|
||||||
|
|
||||||
Http::withHeaders($headers)->post(config('plausible-proxy.domain').'/api/event', $data);
|
|
||||||
|
|
||||||
return response()->json(['status' => 'queued']);
|
|
||||||
});
|
|
||||||
+2
-30
@@ -1,34 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use MattitjaAB\LaravelPlausibleProxy\Http\Controllers\PlausibleScriptProxyController;
|
||||||
|
|
||||||
Route::get('/js/script.js', function () {
|
Route::get('/js/script.js', PlausibleScriptProxyController::class);
|
||||||
$plausibleDomain = config('plausible-proxy.domain');
|
|
||||||
|
|
||||||
if (Cache::has('plausible_script_js')) {
|
|
||||||
return response(Cache::get('plausible_script_js'))
|
|
||||||
->header('Content-Type', 'application/javascript')
|
|
||||||
->header('Cache-Control', 'public, max-age=86400');
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = Http::timeout(5)->get("{$plausibleDomain}/js/script.js");
|
|
||||||
|
|
||||||
if ($response->successful()) {
|
|
||||||
$script = $response->body();
|
|
||||||
Cache::put('plausible_script_js', $script, now()->addHours(6));
|
|
||||||
|
|
||||||
return response($script)
|
|
||||||
->header('Content-Type', 'application/javascript')
|
|
||||||
->header('Cache-Control', 'public, max-age=86400');
|
|
||||||
}
|
|
||||||
|
|
||||||
return response('Error fetching Plausible script', 500);
|
|
||||||
});
|
|
||||||
|
|
||||||
Route::get('/api/routes', function () {
|
|
||||||
return response()->json(
|
|
||||||
collect(Route::getRoutes())->map(fn ($route) => $route->uri())
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace MattitjaAB\LaravelPlausibleProxy\Commands;
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
|
|
||||||
class LaravelPlausibleProxyCommand extends Command
|
|
||||||
{
|
|
||||||
public $signature = 'laravel-plausible-proxy';
|
|
||||||
|
|
||||||
public $description = 'My command';
|
|
||||||
|
|
||||||
public function handle(): int
|
|
||||||
{
|
|
||||||
$this->comment('All done');
|
|
||||||
|
|
||||||
return self::SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace MattitjaAB\LaravelPlausibleProxy\Facades;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Facade;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see \MattitjaAB\LaravelPlausibleProxy\LaravelPlausibleProxy
|
|
||||||
*/
|
|
||||||
class LaravelPlausibleProxy extends Facade
|
|
||||||
{
|
|
||||||
protected static function getFacadeAccessor(): string
|
|
||||||
{
|
|
||||||
return \MattitjaAB\LaravelPlausibleProxy\LaravelPlausibleProxy::class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MattitjaAB\LaravelPlausibleProxy\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use MattitjaAB\LaravelPlausibleProxy\Http\Requests\PlausibleEventRequest;
|
||||||
|
|
||||||
|
class PlausibleEventApiController
|
||||||
|
{
|
||||||
|
public function __invoke(PlausibleEventRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$headers = collect($request->headers->all())
|
||||||
|
->mapWithKeys(fn ($value, $key) => [$key => implode(', ', $value)])
|
||||||
|
->all();
|
||||||
|
|
||||||
|
Http::withHeaders($headers)
|
||||||
|
->post(config('plausible-proxy.domain').'/api/event', $request->validated());
|
||||||
|
|
||||||
|
return response()->json(['status' => 'queued']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MattitjaAB\LaravelPlausibleProxy\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Client\RequestException;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class PlausibleScriptProxyController
|
||||||
|
{
|
||||||
|
public function __invoke(): Response
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$script = Cache::remember(
|
||||||
|
key: 'plausible_script_js',
|
||||||
|
ttl: now()->addHours(6),
|
||||||
|
callback: function () {
|
||||||
|
$plausibleDomain = config('plausible-proxy.domain');
|
||||||
|
|
||||||
|
return Http::timeout(5)
|
||||||
|
->get("{$plausibleDomain}/js/script.js")
|
||||||
|
->throw()
|
||||||
|
->body();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (RequestException $e) {
|
||||||
|
Log::error('Failed to fetch Plausible script: '.$e->getMessage());
|
||||||
|
|
||||||
|
return response('Error fetching Plausible script', 500);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response($script)
|
||||||
|
->header('Content-Type', 'application/javascript')
|
||||||
|
->header('Cache-Control', 'public, max-age=86400');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MattitjaAB\LaravelPlausibleProxy\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class PlausibleEventRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'n' => ['required', 'string'],
|
||||||
|
'u' => ['required', 'url'],
|
||||||
|
'd' => ['required', 'string'],
|
||||||
|
'r' => ['nullable', 'url'],
|
||||||
|
'm' => ['nullable', 'string'],
|
||||||
|
'p' => ['nullable', 'array'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace MattitjaAB\LaravelPlausibleProxy;
|
|
||||||
|
|
||||||
class LaravelPlausibleProxy {}
|
|
||||||
@@ -46,7 +46,7 @@ it('rejects invalid event data', function () {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(422)
|
$response->assertStatus(422)
|
||||||
->assertJsonStructure(['status', 'errors']);
|
->assertJsonValidationErrors(['u' => 'The u field must be a valid URL.']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('accepts valid event data and forwards headers', function () {
|
it('accepts valid event data and forwards headers', function () {
|
||||||
|
|||||||
Reference in new issue
Block a user