Skip to content

Commit

Permalink
prepare for deploy (#9)
Browse files Browse the repository at this point in the history
* move lang directory

* style: apply php-cs-fixer

* add responsecache

* clear cache on content change

* route view

* rate limit services

* throttle web

* add s3 driver
  • Loading branch information
andreiio authored May 4, 2023
1 parent 6591c69 commit 7f42e1d
Show file tree
Hide file tree
Showing 32 changed files with 1,047 additions and 588 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ COPY --from=assets --chown=www-data:www-data /build/public/build /var/www/public
ENV APP_ENV production
ENV APP_DEBUG false
ENV LOG_CHANNEL stderr
ENV RESPONSE_CACHE_ENABLED true

ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME 0

Expand Down
22 changes: 22 additions & 0 deletions app/Concerns/ClearsResponseCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Concerns;

use Spatie\ResponseCache\Facades\ResponseCache;

trait ClearsResponseCache
{
public static function bootClearsResponseCache()
{
self::created(fn () => self::clearResponseCache());
self::updated(fn () => self::clearResponseCache());
self::deleted(fn () => self::clearResponseCache());
}

private static function clearResponseCache(): void
{
ResponseCache::clear();
}
}
6 changes: 3 additions & 3 deletions app/Concerns/InteractsWithSearch.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace App\Concerns;

use App\Models\Ngo;
Expand All @@ -8,11 +10,10 @@

trait InteractsWithSearch
{

public function scopeFilter(Builder $query, Collection $filters): Builder
{
foreach ($filters as $key => $value) {
if (!empty($value)) {
if (! empty($value)) {
if ($this->getModel() === Ngo::getModel()) {
$query->with('services');
match ($key) {
Expand All @@ -22,7 +23,6 @@ public function scopeFilter(Builder $query, Collection $filters): Builder
'county' => $query->where('county_id', $value),
default => $query,
};

} else {
match ($key) {
'intervention_domain' => $query->whereJsonContains('intervention_domains', $value),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function ngoPage(string $local, string $slug)

public function services(Request $request)
{
$query = Service::query()->filter(collect($request->all()))->with(['city', 'county']);
$query = Service::query()->filter(collect($request->all()))->with(['city', 'county']);
$servicesJson = $query->get();
$services = $query->paginate();

Expand Down
1 change: 1 addition & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ class Kernel extends HttpKernel
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'doNotCacheResponse' => \Spatie\ResponseCache\Middlewares\DoNotCacheResponse::class,
];
}
1 change: 0 additions & 1 deletion app/Http/Middleware/LanguageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class LanguageManager
*/
public function handle(Request $request, Closure $next): Response
{

$locale = $request->segment(1);

$locals = ['ro', 'en', 'uk'];
Expand Down
2 changes: 2 additions & 0 deletions app/Models/ActivityDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace App\Models;

use App\Concerns\ClearsResponseCache;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class ActivityDomain extends Model
{
use ClearsResponseCache;
use HasFactory;
use HasTranslations;

Expand Down
2 changes: 2 additions & 0 deletions app/Models/ActivityDomainService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace App\Models;

use App\Concerns\ClearsResponseCache;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Spatie\Translatable\HasTranslations;

class ActivityDomainService extends Model
{
use ClearsResponseCache;
use HasFactory;
use HasTranslations;

Expand Down
2 changes: 2 additions & 0 deletions app/Models/BeneficiaryGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace App\Models;

use App\Concerns\ClearsResponseCache;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class BeneficiaryGroup extends Model
{
use ClearsResponseCache;
use HasFactory;
use HasTranslations;

Expand Down
2 changes: 2 additions & 0 deletions app/Models/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace App\Models;

use App\Concerns\ClearsResponseCache;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class City extends Model
{
use ClearsResponseCache;
use HasFactory;

public function county(): BelongsTo
Expand Down
2 changes: 2 additions & 0 deletions app/Models/County.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace App\Models;

use App\Concerns\ClearsResponseCache;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class County extends Model
{
use ClearsResponseCache;
use HasFactory;

public function cities(): HasMany
Expand Down
2 changes: 2 additions & 0 deletions app/Models/InterventionDomains.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

namespace App\Models;

use App\Concerns\ClearsResponseCache;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class InterventionDomains extends Model
{
use ClearsResponseCache;
use HasFactory;
use HasTranslations;

Expand Down
2 changes: 2 additions & 0 deletions app/Models/Ngo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Concerns\ClearsResponseCache;
use App\Concerns\HasLocation;
use App\Concerns\InteractsWithSearch;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -17,6 +18,7 @@

class Ngo extends Model implements HasMedia
{
use ClearsResponseCache;
use HasFactory;
use InteractsWithMedia;
use HasTranslations;
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace App\Models;

use App\Concerns\ClearsResponseCache;
use App\Concerns\HasLocation;
use App\Concerns\InteractsWithSearch;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Support\Collection;
use Spatie\Translatable\HasTranslations;

class Service extends Model
{
use ClearsResponseCache;
use HasFactory;
use HasTranslations;
use HasLocation;
Expand Down
8 changes: 8 additions & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@ protected function configureRateLimiting(): void
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});

RateLimiter::for('web', function (Request $request) {
return Limit::perMinute(120)->by($request->ip());
});

RateLimiter::for('services', function (Request $request) {
return Limit::perMinute(60)->by($request->ip());
});
}
}
24 changes: 13 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@
"require": {
"php": "^8.1",
"blade-ui-kit/blade-heroicons": "^1.4",
"filament/filament": "^2.0",
"filament/spatie-laravel-media-library-plugin": "^2.0",
"filament/spatie-laravel-translatable-plugin": "^2.0",
"filament/filament": "^2.17",
"filament/spatie-laravel-media-library-plugin": "^2.17",
"filament/spatie-laravel-translatable-plugin": "^2.17",
"guava/filament-icon-picker": "^1.3",
"guzzlehttp/guzzle": "^7.2",
"guzzlehttp/guzzle": "^7.5",
"jeffgreco13/filament-breezy": "^1.5",
"laravel/framework": "^10.0",
"laravel/framework": "^10.9",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8"
"laravel/tinker": "^2.8",
"league/flysystem-aws-s3-v3": "^3.15",
"spatie/laravel-responsecache": "^7.4"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.8",
"fakerphp/faker": "^1.9.1",
"fakerphp/faker": "^1.9",
"friendsofphp/php-cs-fixer": "^3.14",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0"
"mockery/mockery": "^1.4",
"nunomaduro/collision": "^7.5",
"phpunit/phpunit": "^10.1",
"spatie/laravel-ignition": "^2.1"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 7f42e1d

Please sign in to comment.