Playground page calls the runner
3 changed files with 42 additions and 0 deletions
app/Http/Controllers/PlaygroundController.php ADDED
| @@ -0,0 +1,24 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace App\Http\Controllers; | |
| 4 | + | |
| 5 | +use Illuminate\Http\Request; | |
| 6 | +use Illuminate\Support\Facades\Http; | |
| 7 | + | |
| 8 | +class PlaygroundController extends Controller | |
| 9 | +{ | |
| 10 | + public function show() | |
| 11 | + { | |
| 12 | + return view('playground'); | |
| 13 | + } | |
| 14 | + | |
| 15 | + public function run(Request $request) | |
| 16 | + { | |
| 17 | + $data = $request->validate(['language' => 'required|in:python,javascript,go,rust,bash', 'code' => 'required|max:20000']); | |
| 18 | + | |
| 19 | + $response = Http::timeout(config('services.runner.timeout')) | |
| 20 | + ->post(config('services.runner.url').'/run', $data); | |
| 21 | + | |
| 22 | + return response()->json($response->json(), $response->status()); | |
| 23 | + } | |
| 24 | +} | |
config/services.php ADDED
| @@ -0,0 +1,12 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +return [ | |
| 4 | + 'runner' => [ | |
| 5 | + 'url' => env('RUNNER_URL', 'http://127.0.0.1:8088'), | |
| 6 | + 'timeout' => 10, | |
| 7 | + ], | |
| 8 | + 'stripe' => [ | |
| 9 | + 'key' => env('STRIPE_KEY'), | |
| 10 | + 'secret' => env('STRIPE_SECRET'), | |
| 11 | + ], | |
| 12 | +]; | |
routes/api.php ADDED
| @@ -0,0 +1,6 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +use App\Http\Controllers\PlaygroundController; | |
| 4 | +use Illuminate\Support\Facades\Route; | |
| 5 | + | |
| 6 | +Route::post('/run', [PlaygroundController::class, 'run'])->middleware('throttle:20,1'); | |