soiz commited on
Commit
c66f7d7
·
verified ·
1 Parent(s): df49f97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -27
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import os
2
  import shutil
3
- from flask import Flask, send_from_directory, abort, render_template_string
4
- import subprocess
5
 
6
  # リポジトリをクローンするディレクトリ
7
  temp_dir = "/tmp/nebula_repo"
@@ -27,19 +26,15 @@ def clone_and_setup_repo():
27
  os.system("npm run build")
28
  os.system("npm start")
29
 
30
- # index.htmlをカレントディレクトリに移動
31
- index_html_path = os.path.join(temp_dir, 'index.html')
32
- if os.path.exists(index_html_path):
33
- if os.path.exists('index.html'):
34
- os.remove('index.html')
35
- shutil.move(index_html_path, '.')
36
-
37
- # 静的ファイルをstaticディレクトリに移動
38
- # if not os.path.exists('static'):
39
- # os.mkdir('static')
40
- # for item in os.listdir(temp_dir):
41
- # if item != 'index.html':
42
- # shutil.move(os.path.join(temp_dir, item), os.path.join('static', item))
43
 
44
  # クローンとセットアップを実行
45
  clone_and_setup_repo()
@@ -47,20 +42,15 @@ clone_and_setup_repo()
47
  # Flaskアプリケーションの設定
48
  app = Flask(__name__)
49
 
50
- # ルートでindex.htmlを表示
51
  @app.route('/')
52
  def index():
53
- # index.htmlが存在しない場合は404エラー
54
- if not os.path.exists("index.html"):
55
- print("index 404")
56
- return abort(404, description="index.html not found.")
57
-
58
- # index.htmlの内容を読み込む
59
- with open("index.html", "r") as file:
60
- index_html_content = file.read()
61
- print("index.htmlok")
62
 
63
- return render_template_string(index_html_content)
 
64
 
65
  # 静的ファイルを提供するためのルート
66
  @app.route('/<path:filename>')
@@ -77,4 +67,4 @@ def check_main_js():
77
 
78
  if __name__ == '__main__':
79
  # port 7860でFlaskアプリを起動
80
- app.run(host='0.0.0.0', port=7860)
 
1
  import os
2
  import shutil
3
+ from flask import Flask, send_from_directory, abort, render_template
 
4
 
5
  # リポジトリをクローンするディレクトリ
6
  temp_dir = "/tmp/nebula_repo"
 
26
  os.system("npm run build")
27
  os.system("npm start")
28
 
29
+ # views/index.html を templates ディレクトリに移動
30
+ views_index_path = os.path.join(temp_dir, 'views', 'index.html')
31
+ templates_dir = 'templates'
32
+ if os.path.exists(views_index_path):
33
+ if not os.path.exists(templates_dir):
34
+ os.mkdir(templates_dir)
35
+ shutil.move(views_index_path, os.path.join(templates_dir, 'index.html'))
36
+ else:
37
+ print("Error: views/index.html not found in the repository.")
 
 
 
 
38
 
39
  # クローンとセットアップを実行
40
  clone_and_setup_repo()
 
42
  # Flaskアプリケーションの設定
43
  app = Flask(__name__)
44
 
45
+ # ルートでviews/index.htmlを表示
46
  @app.route('/')
47
  def index():
48
+ # templates/index.html が存在しない場合は404エラー
49
+ if not os.path.exists("templates/index.html"):
50
+ return abort(404, description="views/index.html not found.")
 
 
 
 
 
 
51
 
52
+ # Flaskのrender_templateを使用してindex.htmlを表示
53
+ return render_template('index.html')
54
 
55
  # 静的ファイルを提供するためのルート
56
  @app.route('/<path:filename>')
 
67
 
68
  if __name__ == '__main__':
69
  # port 7860でFlaskアプリを起動
70
+ app.run(host='0.0.0.0', port=7860)