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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -1,6 +1,7 @@
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,41 +27,40 @@ def clone_and_setup_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()
41
 
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>')
57
  def static_files(filename):
58
- return send_from_directory('static', filename)
59
 
60
  # main.jsの存在を確認するエンドポイント
61
  @app.route('/check_main_js')
62
  def check_main_js():
63
- if os.path.exists('static/main.js'):
64
  return "main.js exists."
65
  else:
66
  return "main.js does not exist."
 
1
  import os
2
  import shutil
3
  from flask import Flask, send_from_directory, abort, render_template
4
+ import subprocess
5
 
6
  # リポジトリをクローンするディレクトリ
7
  temp_dir = "/tmp/nebula_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
  # クローンとセットアップを実行
38
  clone_and_setup_repo()
39
 
40
  # Flaskアプリケーションの設定
41
+ app = Flask(__name__, template_folder=os.path.join(temp_dir, 'views'))
42
 
43
+ # ルートでindex.htmlを表示
44
  @app.route('/')
45
  def index():
46
+ # index.htmlがリポジトリ内のviewsディレクトリに存在しない場合は404エラー
47
+ index_html_path = os.path.join(temp_dir, 'views', 'index.html')
48
+ if not os.path.exists(index_html_path):
49
+ print("index 404")
50
+ return abort(404, description="index.html not found.")
51
 
52
+ # Flaskのテンプレートエンジンを使ってindex.htmlをレンダリング
53
  return render_template('index.html')
54
 
55
  # 静的ファイルを提供するためのルート
56
  @app.route('/<path:filename>')
57
  def static_files(filename):
58
+ return send_from_directory(os.path.join(temp_dir, 'static'), filename)
59
 
60
  # main.jsの存在を確認するエンドポイント
61
  @app.route('/check_main_js')
62
  def check_main_js():
63
+ if os.path.exists(os.path.join(temp_dir, 'static', 'main.js')):
64
  return "main.js exists."
65
  else:
66
  return "main.js does not exist."