coolify/routes/api.php

89 lines
2.8 KiB
PHP
Raw Normal View History

2023-03-17 15:33:48 +01:00
<?php
use App\Actions\Database\StartMariadb;
2023-10-20 14:58:00 +02:00
use App\Actions\Database\StartMongodb;
use App\Actions\Database\StartMysql;
2023-10-20 14:51:01 +02:00
use App\Actions\Database\StartPostgresql;
2023-10-20 14:58:00 +02:00
use App\Actions\Database\StartRedis;
use App\Actions\Service\StartService;
2024-02-02 11:50:28 +01:00
use App\Http\Controllers\Api\Deploy;
use App\Models\ApplicationDeploymentQueue;
2024-02-01 15:38:12 +01:00
use App\Models\Tag;
2023-09-25 20:57:52 +02:00
use App\Models\User;
2023-12-27 16:45:01 +01:00
use App\Providers\RouteServiceProvider;
2023-10-20 14:51:01 +02:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
2023-03-17 15:33:48 +01:00
use Illuminate\Support\Facades\Route;
2023-10-20 14:51:01 +02:00
use Visus\Cuid2\Cuid2;
2023-03-17 15:33:48 +01:00
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/
$middlewares = ['auth:sanctum'];
if (isDev()) {
$middlewares = [];
}
2023-04-28 11:06:55 +02:00
Route::get('/health', function () {
return 'OK';
2023-03-17 15:33:48 +01:00
});
Route::post('/feedback', function (Request $request) {
$content = $request->input('content');
$webhook_url = config('coolify.feedback_discord_webhook');
if ($webhook_url) {
Http::post($webhook_url, [
'content' => $content
]);
}
return response()->json(['message' => 'Feedback sent.'], 200);
});
2024-02-02 11:50:28 +01:00
// Route::group([
// 'middleware' => $middlewares,
// 'prefix' => 'v1'
// ], function () {
// Route::get('/deployments', function () {
// return ApplicationDeploymentQueue::whereIn("status", ["in_progress", "queued"])->get([
// "id",
// "server_id",
// "status"
// ])->groupBy("server_id")->map(function ($item) {
// return $item;
// })->toArray();
// });
// });
2023-10-20 14:51:01 +02:00
Route::group([
'middleware' => ['auth:sanctum'],
'prefix' => 'v1'
], function () {
2024-02-02 11:50:28 +01:00
Route::get('/deploy', [Deploy::class, 'deploy']);
2023-10-20 14:51:01 +02:00
});
2023-09-25 20:57:52 +02:00
Route::middleware(['throttle:5'])->group(function () {
2023-10-20 14:51:01 +02:00
Route::get('/unsubscribe/{token}', function () {
2023-09-25 20:57:52 +02:00
try {
$token = request()->token;
$email = decrypt($token);
if (!User::whereEmail($email)->exists()) {
2023-12-27 16:45:01 +01:00
return redirect(RouteServiceProvider::HOME);
2023-09-25 20:57:52 +02:00
}
if (User::whereEmail($email)->first()->marketing_emails === false) {
return 'You have already unsubscribed from marketing emails.';
}
User::whereEmail($email)->update(['marketing_emails' => false]);
return 'You have been unsubscribed from marketing emails.';
} catch (\Throwable $e) {
return 'Something went wrong. Please try again or contact support.';
}
})->name('unsubscribe.marketing.emails');
});