158 lines
7.0 KiB
PHP
158 lines
7.0 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\Api\Admin\AdminResourceController;
|
|
use App\Http\Controllers\Api\Admin\CommentAdminController;
|
|
use App\Http\Controllers\Api\AuthController;
|
|
use App\Http\Controllers\Api\Blog\CategoryController;
|
|
use App\Http\Controllers\Api\Blog\CommentController;
|
|
use App\Http\Controllers\Api\Blog\HomeController;
|
|
use App\Http\Controllers\Api\Blog\PostController;
|
|
use App\Http\Controllers\Api\Blog\PostInteractionController;
|
|
use App\Http\Controllers\Api\Blog\TagController;
|
|
use App\Http\Controllers\Api\ContactMessageController;
|
|
use App\Http\Controllers\Api\NewsletterSubscriptionController;
|
|
use App\Http\Controllers\Api\Website\AboutMeController;
|
|
use App\Http\Controllers\Api\Website\ProjectCategoryController;
|
|
use App\Http\Controllers\Api\Website\ProjectController;
|
|
use App\Http\Controllers\Api\Website\ServiceController;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Authentication
|
|
|--------------------------------------------------------------------------
|
|
| Used by the admin panel. Login is throttled hard because it is the one
|
|
| endpoint that accepts attacker-controlled credentials.
|
|
*/
|
|
|
|
Route::post('auth/login', [AuthController::class, 'login'])
|
|
->middleware('throttle:5,1')
|
|
->name('auth.login');
|
|
|
|
Route::middleware(['auth:sanctum', 'throttle:60,1'])->group(function () {
|
|
Route::get('auth/me', [AuthController::class, 'me'])->name('auth.me');
|
|
Route::post('auth/logout', [AuthController::class, 'logout'])->name('auth.logout');
|
|
});
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Public read API
|
|
|--------------------------------------------------------------------------
|
|
| Anonymous, cacheable, GET-only. Nothing here can change state.
|
|
*/
|
|
|
|
Route::middleware('throttle:60,1')->group(function () {
|
|
Route::prefix('website')->group(function () {
|
|
Route::get('about-me', [AboutMeController::class, 'index']);
|
|
Route::get('about-me/{id}', [AboutMeController::class, 'show']);
|
|
Route::get('about-me/{id}/translation/{locale}', [AboutMeController::class, 'getTranslation']);
|
|
|
|
Route::get('project-categories', [ProjectCategoryController::class, 'index']);
|
|
|
|
Route::get('services/{locale}', [ServiceController::class, 'index']);
|
|
Route::get('services/{id}/translation/{locale}', [ServiceController::class, 'showTranslation']);
|
|
|
|
Route::get('projects/translation/{locale}', [ProjectController::class, 'index']);
|
|
Route::get('projects/{id}/translation/{locale}', [ProjectController::class, 'show']);
|
|
});
|
|
|
|
Route::prefix('blog')->group(function () {
|
|
Route::get('homepage', [HomeController::class, 'index']);
|
|
|
|
Route::get('posts', [PostController::class, 'index']);
|
|
Route::get('posts/{slug}', [PostController::class, 'show']);
|
|
Route::get('posts/{slug}/comments', [CommentController::class, 'index']);
|
|
|
|
Route::get('categories', [CategoryController::class, 'index']);
|
|
Route::get('categories/{id}', [CategoryController::class, 'show']);
|
|
Route::get('categories/{slug}/posts', [CategoryController::class, 'getCategoryWithPosts']);
|
|
|
|
Route::get('tags', [TagController::class, 'index']);
|
|
Route::get('tags/by-slug/{slug}/posts', [TagController::class, 'getTagWithPosts']);
|
|
Route::get('tags/{id}', [TagController::class, 'show']);
|
|
});
|
|
});
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Public contact form
|
|
|--------------------------------------------------------------------------
|
|
| The site has no mail service; messages are stored and read from the admin
|
|
| panel, so the write endpoint is public (no auth) but throttled to keep
|
|
| spam from flooding the inbox.
|
|
*/
|
|
|
|
Route::post('contact', [ContactMessageController::class, 'store'])
|
|
->middleware('throttle:5,1');
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Newsletter subscriptions
|
|
|--------------------------------------------------------------------------
|
|
| Stored and read from the admin panel like contact messages, so the write
|
|
| endpoint is public (no auth) but throttled the same way.
|
|
*/
|
|
|
|
Route::post('newsletter/subscribe', [NewsletterSubscriptionController::class, 'subscribe'])
|
|
->middleware('throttle:5,1');
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Public blog interactions
|
|
|--------------------------------------------------------------------------
|
|
| Anonymous but mutating, so each endpoint is throttled: comment submission
|
|
| is slow like the contact form, view/like counters are faster because they
|
|
| are single-column increments triggered once per page load.
|
|
*/
|
|
|
|
Route::middleware('throttle:60,1')->group(function () {
|
|
Route::prefix('blog')->group(function () {
|
|
Route::post('posts/{slug}/view', [PostInteractionController::class, 'view']);
|
|
Route::post('posts/{slug}/like', [PostInteractionController::class, 'like']);
|
|
});
|
|
});
|
|
|
|
Route::post('blog/posts/{slug}/comments', [CommentController::class, 'store'])
|
|
->middleware('throttle:5,1');
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Admin write API
|
|
|--------------------------------------------------------------------------
|
|
| Every mutating endpoint requires an authenticated admin. These routes were
|
|
| previously anonymous, which allowed anyone to create, edit or delete every
|
|
| post, category, tag, project and about-me record on the live site.
|
|
*/
|
|
|
|
Route::middleware(['auth:sanctum', 'admin', 'throttle:30,1'])->group(function () {
|
|
Route::prefix('website')->group(function () {
|
|
Route::post('about-me', [AboutMeController::class, 'store']);
|
|
Route::put('about-me/{id}', [AboutMeController::class, 'update']);
|
|
Route::delete('about-me/{id}', [AboutMeController::class, 'destroy']);
|
|
|
|
Route::post('projects', [ProjectController::class, 'store']);
|
|
Route::put('projects/{id}', [ProjectController::class, 'update']);
|
|
Route::delete('projects/{id}', [ProjectController::class, 'destroy']);
|
|
});
|
|
|
|
Route::prefix('blog')->group(function () {
|
|
Route::post('posts', [PostController::class, 'store']);
|
|
Route::put('posts/{id}', [PostController::class, 'update']);
|
|
Route::delete('posts/{id}', [PostController::class, 'destroy']);
|
|
|
|
Route::get('comments', [CommentAdminController::class, 'index']);
|
|
Route::put('comments/{id}', [CommentAdminController::class, 'update']);
|
|
Route::delete('comments/{id}', [CommentAdminController::class, 'destroy']);
|
|
|
|
Route::post('categories', [CategoryController::class, 'store']);
|
|
Route::put('categories/{id}', [CategoryController::class, 'update']);
|
|
Route::delete('categories/{id}', [CategoryController::class, 'destroy']);
|
|
|
|
Route::post('tags', [TagController::class, 'store']);
|
|
Route::put('tags/{id}', [TagController::class, 'update']);
|
|
Route::delete('tags/{id}', [TagController::class, 'destroy']);
|
|
});
|
|
|
|
Route::get('admin/resources/{resource}', [AdminResourceController::class, 'index']);
|
|
});
|