coolify/routes/web.php

172 lines
6.4 KiB
PHP
Raw Normal View History

2023-03-17 15:33:48 +01:00
<?php
2023-04-19 12:42:15 +02:00
use App\Http\Controllers\ApplicationController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\ProjectController;
2023-04-25 09:38:05 +02:00
use App\Models\InstanceSettings;
2023-05-03 12:38:57 +02:00
use App\Models\PrivateKey;
2023-05-02 12:47:52 +02:00
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
2023-05-03 07:23:45 +02:00
use App\Http\Controllers\ServerController;
2023-05-08 13:36:49 +02:00
use App\Models\GithubApp;
use App\Models\Project;
2023-05-04 11:14:37 +02:00
use App\Models\Server;
2023-05-08 13:36:49 +02:00
use Illuminate\Http\Request;
2023-03-17 15:33:48 +01:00
use Illuminate\Support\Facades\Route;
2023-05-08 21:56:44 +02:00
use Illuminate\Support\Str;
2023-03-17 15:33:48 +01:00
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
2023-03-20 13:04:22 +01:00
Route::middleware(['auth'])->group(function () {
2023-04-25 09:38:05 +02:00
Route::get('/', function () {
2023-05-08 13:36:49 +02:00
$id = session('currentTeam')->id;
$projects = Project::where('team_id', $id)->get();
$servers = Server::where('team_id', $id)->get();
2023-05-02 12:47:52 +02:00
$destinations = $servers->map(function ($server) {
return $server->standaloneDockers->merge($server->swarmDockers);
})->flatten();
2023-05-08 13:36:49 +02:00
$private_keys = PrivateKey::where('team_id', $id)->get();
$github_apps = GithubApp::private();
2023-04-25 11:01:56 +02:00
return view('dashboard', [
2023-04-25 10:47:13 +02:00
'servers' => $servers->sortBy('name'),
2023-05-02 12:47:52 +02:00
'projects' => $projects->sortBy('name'),
'destinations' => $destinations->sortBy('name'),
2023-05-03 12:38:57 +02:00
'private_keys' => $private_keys->sortBy('name'),
2023-05-08 13:36:49 +02:00
'github_apps' => $github_apps->sortBy('name'),
2023-04-25 09:38:05 +02:00
]);
2023-04-25 11:01:56 +02:00
})->name('dashboard');
Route::get('/profile', function () {
return view('profile');
2023-04-25 09:38:05 +02:00
})->name('profile');
Route::get('/settings', function () {
$isRoot = auth()->user()->isRoot();
if ($isRoot) {
$settings = InstanceSettings::find(0);
return view('settings', [
'settings' => $settings
]);
} else {
2023-04-25 14:43:35 +02:00
return redirect()->route('dashboard');
2023-04-25 09:38:05 +02:00
}
})->name('settings');
2023-04-14 10:00:42 +02:00
Route::get('/update', function () {
return view('update');
2023-04-25 09:38:05 +02:00
})->name('update');
2023-05-04 10:00:08 +02:00
Route::get('/command-center', function () {
return view('command-center');
})->name('command-center');
2023-04-25 09:38:05 +02:00
});
2023-05-03 12:38:57 +02:00
Route::middleware(['auth'])->group(function () {
Route::get('/private-key/new', fn () => view('private-key.new'))->name('private-key.new');
Route::get('/private-key/{private_key_uuid}', function () {
$private_key = PrivateKey::where('uuid', request()->private_key_uuid)->first();
return view('private-key.show', [
'private_key' => $private_key,
]);
})->name('private-key.show');
});
2023-05-08 13:36:49 +02:00
Route::middleware(['auth'])->group(function () {
Route::get('/source/new', fn () => view('source.new'))->name('source.new');
Route::get('/source/github/{github_app_uuid}', function (Request $request) {
2023-05-09 11:33:50 +02:00
$github_app = GithubApp::where('uuid', request()->github_app_uuid)->first();
2023-05-09 14:42:10 +02:00
$name = Str::of(Str::kebab($github_app->name))->start('coolify-');
2023-05-08 21:56:44 +02:00
$settings = InstanceSettings::first();
$host = $request->schemeAndHttpHost();
if ($settings->fqdn) {
$host = $settings->fqdn;
}
2023-05-09 11:33:50 +02:00
$installation_path = $github_app->html_url === 'https://github.com' ? 'apps' : 'github-apps';
$installation_url = "$github_app->html_url/$installation_path/$name/installations/new";
2023-05-08 21:56:44 +02:00
return view('source.github.show', [
'github_app' => $github_app,
'host' => $host,
2023-05-09 11:33:50 +02:00
'name' => $name,
'installation_url' => $installation_url,
2023-05-08 21:56:44 +02:00
]);
2023-05-08 13:36:49 +02:00
})->name('source.github.show');
});
2023-04-25 10:47:13 +02:00
Route::middleware(['auth'])->group(function () {
Route::get('/server/new', fn () => view('server.new'))->name('server.new');
2023-04-25 10:47:13 +02:00
Route::get('/server/{server_uuid}', function () {
$server = session('currentTeam')->load(['servers'])->servers->firstWhere('uuid', request()->server_uuid);
if (!$server) {
abort(404);
}
return view('server.show', [
2023-05-02 12:47:52 +02:00
'server' => $server,
2023-04-25 10:47:13 +02:00
]);
})->name('server.show');
2023-05-03 12:38:57 +02:00
Route::get('/server/{server_uuid}/private-key', function () {
return view('server.private-key');
})->name('server.private-key');
2023-04-25 10:47:13 +02:00
});
2023-05-02 12:47:52 +02:00
Route::middleware(['auth'])->group(function () {
2023-05-03 11:16:08 +02:00
Route::get('/destination/new', function () {
2023-05-08 09:16:50 +02:00
$servers = Server::validated();
2023-05-03 11:16:08 +02:00
return view('destination.new', [
2023-05-04 11:14:37 +02:00
"servers" => $servers,
2023-05-03 11:16:08 +02:00
]);
})->name('destination.new');
2023-05-02 12:47:52 +02:00
Route::get('/destination/{destination_uuid}', function () {
$standalone_dockers = StandaloneDocker::where('uuid', request()->destination_uuid)->first();
$swarm_dockers = SwarmDocker::where('uuid', request()->destination_uuid)->first();
if (!$standalone_dockers && !$swarm_dockers) {
abort(404);
}
$destination = $standalone_dockers ? $standalone_dockers : $swarm_dockers;
return view('destination.show', [
2023-05-04 11:14:37 +02:00
'destination' => $destination->load(['server']),
2023-05-02 12:47:52 +02:00
]);
})->name('destination.show');
});
2023-04-25 09:38:05 +02:00
Route::middleware(['auth'])->group(function () {
2023-04-26 13:25:41 +02:00
Route::get('/project/new', fn () => view('project.new', ['type' => 'project']))->name('project.new');
2023-04-25 09:38:05 +02:00
Route::get(
'/project/{project_uuid}',
[ProjectController::class, 'environments']
)->name('project.environments');
2023-04-26 13:25:41 +02:00
Route::get(
'/project/{project_uuid}/{environment_name}/new',
[ProjectController::class, 'resources_new']
)->name('project.resources.new');
2023-04-25 09:38:05 +02:00
Route::get(
'/project/{project_uuid}/{environment_name}',
[ProjectController::class, 'resources']
)->name('project.resources');
Route::get(
'/project/{project_uuid}/{environment_name}/application/{application_uuid}',
[ApplicationController::class, 'configuration']
2023-04-25 11:01:56 +02:00
)->name('project.application.configuration');
2023-04-25 09:38:05 +02:00
Route::get(
'/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment',
[ApplicationController::class, 'deployments']
2023-04-25 11:01:56 +02:00
)->name('project.application.deployments');
2023-04-25 09:38:05 +02:00
Route::get(
'/project/{project_uuid}/{environment_name}/application/{application_uuid}/deployment/{deployment_uuid}',
[ApplicationController::class, 'deployment']
2023-04-25 11:01:56 +02:00
)->name('project.application.deployment');
});