Update app.py
Browse files
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 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
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 |
-
# ルートで
|
46 |
@app.route('/')
|
47 |
def index():
|
48 |
-
#
|
49 |
-
|
50 |
-
|
|
|
|
|
51 |
|
52 |
-
# Flask
|
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
|
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."
|