| |
| begin |
| require "bundler/setup" |
| rescue Bundler::PermissionError => e |
| |
| require "sinatra" |
| require "json" |
| require "puma" |
| rescue LoadError => e |
| puts "Bundler non disponible, chargement manuel des gems" |
| require "sinatra" |
| require "json" |
| end |
|
|
| class MonApp < Sinatra::Base |
| configure do |
| set :port, 7860 |
| set :bind, "0.0.0.0" |
| set :server, :puma |
| end |
|
|
| |
| get "/" do |
| content_type :html |
| <<~HTML |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>Mon Application Ruby</title> |
| <style> |
| body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; } |
| .container { background: #f5f5f5; padding: 20px; border-radius: 10px; } |
| input, button { padding: 10px; margin: 5px; } |
| .result { background: white; padding: 15px; border-radius: 5px; margin-top: 10px; } |
| </style> |
| </head> |
| <body> |
| <div class="container"> |
| <h1>🚀 Mon Application Ruby</h1> |
| <p>Application démarrée avec succès!</p> |
| |
| <h2>Testez l'API</h2> |
| |
| <div> |
| <h3>Saluer quelqu'un</h3> |
| <input type="text" id="nameInput" placeholder="Votre nom" value="Monde"> |
| <button onclick="greet()">Saluer</button> |
| <div id="greetResult" class="result"></div> |
| </div> |
| |
| <div> |
| <h3>Santé de l'application</h3> |
| <button onclick="checkHealth()">Vérifier</button> |
| <div id="healthResult" class="result"></div> |
| </div> |
| </div> |
| |
| <script> |
| async function greet() { |
| const name = document.getElementById('nameInput').value || 'Monde'; |
| const response = await fetch(`/hello/${encodeURIComponent(name)}`); |
| const data = await response.json(); |
| document.getElementById('greetResult').innerHTML = JSON.stringify(data, null, 2); |
| } |
| |
| async function checkHealth() { |
| const response = await fetch('/health'); |
| const data = await response.json(); |
| document.getElementById('healthResult').innerHTML = JSON.stringify(data, null, 2); |
| } |
| </script> |
| </body> |
| </html> |
| HTML |
| end |
|
|
| get "/hello/:name" do |
| content_type :json |
| { |
| message: "Bonjour #{params[:name]}!", |
| status: "success", |
| timestamp: Time.now.iso8601, |
| }.to_json |
| end |
|
|
| get "/health" do |
| content_type :json |
| { |
| status: "OK", |
| version: "1.0.0", |
| ruby_version: RUBY_VERSION, |
| }.to_json |
| end |
| end |
|
|