File size: 2,815 Bytes
5a640eb
9b33bc1
 
 
 
 
 
 
 
 
 
 
 
5a640eb
 
 
 
 
 
 
 
9b33bc1
5a640eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b33bc1
5a640eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# app.rb
begin
  require "bundler/setup"
rescue Bundler::PermissionError => e
  # Fallback: charger les gems manuellement si Bundler échoue
  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

  # ... le reste de votre code reste inchangé ...
  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