16 Commits
Author SHA1 Message Date
Mathias fa4784c8ec Merge pull request #8 from MattitjaAB/cleanup
Cleanup
2025-06-25 21:34:33 +02:00
mathiaspalmqvist cd00572702 WIP 2025-06-25 21:33:15 +02:00
mathiaspalmqvist 8c042b27cf WIP 2025-06-25 21:31:35 +02:00
mathiaspalmqvist 4aa046d7a7 Merge branch 'cleanup' of https://github.com/MattitjaAB/laravel-plausible-proxy into cleanup 2025-06-25 21:30:22 +02:00
mathiaspalmqvist 859dcf99be Cleanup 2025-06-25 21:30:16 +02:00
mathiaspalmqvist 2893ed0bc6 Fix styling 2025-06-25 19:27:34 +00:00
mathiaspalmqvist 15e9fcc186 Clean 2025-06-25 21:21:07 +02:00
mathiaspalmqvist 42404cc2cc Cleanup 2025-06-25 21:10:11 +02:00
mathiaspalmqvist b53047a28c Update CHANGELOG 2025-06-16 20:38:09 +00:00
Mathias 5eff0cafe5 Merge pull request #7 from MattitjaAB/6-laravel-12
Added support for L12
2025-06-16 22:32:57 +02:00
mathiaspalmqvist 0e25ead520 Added support for L12 2025-06-16 22:30:57 +02:00
github-actions[bot] 67507d036a Merge pull request #4 from MattitjaAB/dependabot/github_actions/dependabot/fetch-metadata-2.4.0
Bump dependabot/fetch-metadata from 2.3.0 to 2.4.0
2025-05-12 03:49:36 +00:00
dependabot[bot] 0ce7b51eff Bump dependabot/fetch-metadata from 2.3.0 to 2.4.0
Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 2.3.0 to 2.4.0.
- [Release notes](https://github.com/dependabot/fetch-metadata/releases)
- [Commits](https://github.com/dependabot/fetch-metadata/compare/v2.3.0...v2.4.0)

---
updated-dependencies:
- dependency-name: dependabot/fetch-metadata
  dependency-version: 2.4.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-12 03:49:27 +00:00
github-actions[bot] 891c3d8ff8 Merge pull request #3 from MattitjaAB/dependabot/github_actions/aglipanci/laravel-pint-action-2.5
Bump aglipanci/laravel-pint-action from 2.4 to 2.5
2025-02-03 03:46:55 +00:00
dependabot[bot] e2062499ae Bump aglipanci/laravel-pint-action from 2.4 to 2.5
Bumps [aglipanci/laravel-pint-action](https://github.com/aglipanci/laravel-pint-action) from 2.4 to 2.5.
- [Release notes](https://github.com/aglipanci/laravel-pint-action/releases)
- [Commits](https://github.com/aglipanci/laravel-pint-action/compare/2.4...2.5)

---
updated-dependencies:
- dependency-name: aglipanci/laravel-pint-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-02-03 03:46:39 +00:00
mathiaspalmqvist 1f4bbadab7 Update CHANGELOG 2025-01-31 13:19:59 +00:00
19 changed files with 143 additions and 150 deletions

No files matched your search

+1 -1
View File
@@ -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
+26 -4
View File
@@ -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
+22
View File
@@ -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
+2 -2
View File
@@ -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
View File
@@ -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",
-19
View File
@@ -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
View File
@@ -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
View File
Whitespace-only changes.
+2 -31
View File
@@ -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
View File
@@ -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;
}
}
-16
View File
@@ -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'],
];
}
}
-5
View File
@@ -1,5 +0,0 @@
<?php
namespace MattitjaAB\LaravelPlausibleProxy;
class LaravelPlausibleProxy {}
+1 -1
View File
@@ -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 () {