Nambinintsoa Rovatiana RAMAROSON commited on
Commit
9b33bc1
·
1 Parent(s): d759efc

test running app - change app.rb

Browse files
Files changed (1) hide show
  1. app.rb +14 -52
app.rb CHANGED
@@ -1,6 +1,16 @@
1
  # app.rb
2
- require "sinatra"
3
- require "json"
 
 
 
 
 
 
 
 
 
 
4
 
5
  class MonApp < Sinatra::Base
6
  configure do
@@ -9,7 +19,7 @@ class MonApp < Sinatra::Base
9
  set :server, :puma
10
  end
11
 
12
- # Page d'accueil avec interface simple
13
  get "/" do
14
  content_type :html
15
  <<~HTML
@@ -27,6 +37,7 @@ class MonApp < Sinatra::Base
27
  <body>
28
  <div class="container">
29
  <h1>🚀 Mon Application Ruby</h1>
 
30
 
31
  <h2>Testez l'API</h2>
32
 
@@ -37,14 +48,6 @@ class MonApp < Sinatra::Base
37
  <div id="greetResult" class="result"></div>
38
  </div>
39
 
40
- <div>
41
- <h3>Créer un utilisateur</h3>
42
- <input type="text" id="userName" placeholder="Nom">
43
- <input type="email" id="userEmail" placeholder="Email">
44
- <button onclick="createUser()">Créer</button>
45
- <div id="userResult" class="result"></div>
46
- </div>
47
-
48
  <div>
49
  <h3>Santé de l'application</h3>
50
  <button onclick="checkHealth()">Vérifier</button>
@@ -60,19 +63,6 @@ class MonApp < Sinatra::Base
60
  document.getElementById('greetResult').innerHTML = JSON.stringify(data, null, 2);
61
  }
62
 
63
- async function createUser() {
64
- const name = document.getElementById('userName').value;
65
- const email = document.getElementById('userEmail').value;
66
-
67
- const response = await fetch('/users', {
68
- method: 'POST',
69
- headers: { 'Content-Type': 'application/json' },
70
- body: JSON.stringify({ name, email })
71
- });
72
- const data = await response.json();
73
- document.getElementById('userResult').innerHTML = JSON.stringify(data, null, 2);
74
- }
75
-
76
  async function checkHealth() {
77
  const response = await fetch('/health');
78
  const data = await response.json();
@@ -84,7 +74,6 @@ class MonApp < Sinatra::Base
84
  HTML
85
  end
86
 
87
- # API Routes
88
  get "/hello/:name" do
89
  content_type :json
90
  {
@@ -94,39 +83,12 @@ class MonApp < Sinatra::Base
94
  }.to_json
95
  end
96
 
97
- post "/users" do
98
- content_type :json
99
- data = JSON.parse(request.body.read)
100
-
101
- {
102
- message: "Utilisateur créé avec succès",
103
- user: data,
104
- id: rand(1000..9999),
105
- created_at: Time.now.iso8601,
106
- }.to_json
107
- end
108
-
109
  get "/health" do
110
  content_type :json
111
  {
112
  status: "OK",
113
  version: "1.0.0",
114
  ruby_version: RUBY_VERSION,
115
- environment: ENV["RACK_ENV"] || "development",
116
- }.to_json
117
- end
118
-
119
- # Route pour les informations sur l'API
120
- get "/api" do
121
- content_type :json
122
- {
123
- endpoints: [
124
- { method: "GET", path: "/", description: "Interface web" },
125
- { method: "GET", path: "/hello/:name", description: "Salutation personnalisée" },
126
- { method: "POST", path: "/users", description: "Créer un utilisateur" },
127
- { method: "GET", path: "/health", description: 'Santé de l\'application' },
128
- { method: "GET", path: "/api", description: 'Documentation de l\'API' },
129
- ],
130
  }.to_json
131
  end
132
  end
 
1
  # app.rb
2
+ begin
3
+ require "bundler/setup"
4
+ rescue Bundler::PermissionError => e
5
+ # Fallback: charger les gems manuellement si Bundler échoue
6
+ require "sinatra"
7
+ require "json"
8
+ require "puma"
9
+ rescue LoadError => e
10
+ puts "Bundler non disponible, chargement manuel des gems"
11
+ require "sinatra"
12
+ require "json"
13
+ end
14
 
15
  class MonApp < Sinatra::Base
16
  configure do
 
19
  set :server, :puma
20
  end
21
 
22
+ # ... le reste de votre code reste inchangé ...
23
  get "/" do
24
  content_type :html
25
  <<~HTML
 
37
  <body>
38
  <div class="container">
39
  <h1>🚀 Mon Application Ruby</h1>
40
+ <p>Application démarrée avec succès!</p>
41
 
42
  <h2>Testez l'API</h2>
43
 
 
48
  <div id="greetResult" class="result"></div>
49
  </div>
50
 
 
 
 
 
 
 
 
 
51
  <div>
52
  <h3>Santé de l'application</h3>
53
  <button onclick="checkHealth()">Vérifier</button>
 
63
  document.getElementById('greetResult').innerHTML = JSON.stringify(data, null, 2);
64
  }
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  async function checkHealth() {
67
  const response = await fetch('/health');
68
  const data = await response.json();
 
74
  HTML
75
  end
76
 
 
77
  get "/hello/:name" do
78
  content_type :json
79
  {
 
83
  }.to_json
84
  end
85
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  get "/health" do
87
  content_type :json
88
  {
89
  status: "OK",
90
  version: "1.0.0",
91
  ruby_version: RUBY_VERSION,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  }.to_json
93
  end
94
  end