Skip to content

Commit 12ca173

Browse files
committed
add health and word endpoint
1 parent ade967a commit 12ca173

15 files changed

+106
-266
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ DB_PORT=3306
44
DB_DATABASE=laravel_php_mariadb_demo
55
DB_USERNAME=root
66
DB_PASSWORD=
7+
8+
SESSION_DRIVER=file

apache/000-default.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<VirtualHost *:80>
2+
DocumentRoot /var/www/html/public
3+
<Directory /var/www/html/public>
4+
AllowOverride All
5+
Require all granted
6+
</Directory>
7+
</VirtualHost>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
// app/Http/Controllers/HealthController.php
4+
namespace App\Http\Controllers;
5+
6+
use Illuminate\Http\Request;
7+
8+
class HealthController extends Controller
9+
{
10+
public function checkHealth()
11+
{
12+
return response()->json(['status' => 'healthy']);
13+
}
14+
}

app/Models/User.php

Lines changed: 0 additions & 48 deletions
This file was deleted.

app/Models/Word.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ class Word extends Model
99
{
1010
use HasFactory;
1111

12+
protected $table = 'words';
1213
protected $fillable = ['word'];
1314
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Cache\RateLimiting\Limit;
6+
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7+
use Illuminate\Http\Request;
8+
use Illuminate\Support\Facades\RateLimiter;
9+
use Illuminate\Support\Facades\Route;
10+
11+
class RouteServiceProvider extends ServiceProvider
12+
{
13+
/**
14+
* The path to the "home" route for your application.
15+
*
16+
* Typically, users are redirected here after authentication.
17+
*
18+
* @var string
19+
*/
20+
public const HOME = '/';
21+
22+
/**
23+
* Define your route model bindings, pattern filters, and other route configuration.
24+
*/
25+
public function boot(): void
26+
{
27+
$this->configureRateLimiting();
28+
29+
$this->routes(function () {
30+
Route::prefix('api')
31+
->middleware('api')
32+
->namespace($this->namespace)
33+
->group(base_path('routes/api.php'));
34+
35+
Route::middleware(['web'])
36+
->group(base_path('routes/web.php'));
37+
});
38+
}
39+
40+
/**
41+
* Configure the rate limiters for the application.
42+
*/
43+
protected function configureRateLimiting(): void
44+
{
45+
RateLimiter::for('api', function (Request $request) {
46+
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
47+
});
48+
}
49+
}

bootstrap/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
return Application::configure(basePath: dirname(__DIR__))
88
->withRouting(
99
web: __DIR__.'/../routes/web.php',
10+
api: __DIR__ . '/../routes/api.php',
1011
commands: __DIR__.'/../routes/console.php',
1112
health: '/up',
1213
)

database/factories/UserFactory.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

database/migrations/0001_01_01_000000_create_users_table.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

database/migrations/0001_01_01_000001_create_cache_table.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)