GPTfree api commited on
Commit
836b041
·
verified ·
1 Parent(s): a13a30b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"
8
+
9
+ # リポジトリのクローンとセットアップを行う
10
+ def clone_and_setup_repo():
11
+ # 一時ディレクトリが存在する場合は削除
12
+ if os.path.exists(temp_dir):
13
+ shutil.rmtree(temp_dir)
14
+
15
+ print("Cloning the repository...")
16
+ result = os.system(f"git clone https://github.com/izum00/Alu.git --recursive {temp_dir}")
17
+
18
+ if result != 0:
19
+ print("Error: Failed to clone the repository.")
20
+ return
21
+
22
+ # クローンしたディレクトリに移動してセットアップ
23
+ os.chdir(temp_dir)
24
+ os.system("npm i")
25
+ os.system("cp .env.example .env")
26
+ os.system("npm i -g pnpm")
27
+ os.system("pnpm i")
28
+ os.system("npm run build")
29
+ os.system("npm start")
30
+ os.system("npm restart")
31
+
32
+ # index.htmlをカレントディレクトリに移動
33
+ index_html_path = os.path.join(temp_dir, 'index.html')
34
+ if os.path.exists(index_html_path):
35
+ if os.path.exists('index.html'):
36
+ os.remove('index.html')
37
+ shutil.move(index_html_path, '.')
38
+
39
+ # クローンとセットアップを実行
40
+ clone_and_setup_repo()
41
+
42
+ # Flaskアプリケーションの設定
43
+ app = Flask(__name__, template_folder=os.path.join(temp_dir, 'views'))
44
+
45
+ # ルートでindex.htmlを表示
46
+ @app.route('/')
47
+ def index():
48
+ # index.htmlがリポジトリ内のviewsディレクトリに存在しない場合は404エラー
49
+ index_html_path = os.path.join(temp_dir, 'views', 'index.html')
50
+ if not os.path.exists(index_html_path):
51
+ print("index 404")
52
+ return abort(404, description="index.html not found.")
53
+
54
+ # Flaskのテンプレートエンジンを使ってindex.htmlをレンダリング
55
+ return render_template('index.html')
56
+
57
+ # 静的ファイルを提供するためのルート
58
+ @app.route('/<path:filename>')
59
+ def static_files(filename):
60
+ return send_from_directory(os.path.join(temp_dir, 'views'), filename)
61
+
62
+ # main.jsの存在を確認するエンドポイント
63
+ @app.route('/check_main_js')
64
+ def check_main_js():
65
+ if os.path.exists(os.path.join(temp_dir, 'static', 'main.js')):
66
+ return "main.js exists."
67
+ else:
68
+ return "main.js does not exist."
69
+
70
+ if __name__ == '__main__':
71
+ # port 7860でFlaskアプリを起動
72
+ app.run(host='0.0.0.0', port=7860)