import os import shutil from flask import Flask, send_from_directory, abort, render_template # リポジトリをクローンするディレクトリ temp_dir = "/tmp/nebula_repo" # リポジトリのクローンとセットアップを行う def clone_and_setup_repo(): # 一時ディレクトリが存在する場合は削除 if os.path.exists(temp_dir): shutil.rmtree(temp_dir) print("Cloning the repository...") result = os.system(f"git clone https://github.com/izum00/Holy-Unblocker.git --recursive {temp_dir}") if result != 0: print("Error: Failed to clone the repository.") return # クローンしたディレクトリに移動してセットアップ os.chdir(temp_dir) os.system("npm i") os.system("cp .env.example .env") os.system("nano .env") os.system("npm run build") os.system("npm start") # views/index.html を templates ディレクトリに移動 views_index_path = os.path.join(temp_dir, 'views', 'index.html') templates_dir = 'templates' if os.path.exists(views_index_path): if not os.path.exists(templates_dir): os.mkdir(templates_dir) shutil.move(views_index_path, os.path.join(templates_dir, 'index.html')) else: print("Error: views/index.html not found in the repository.") # クローンとセットアップを実行 clone_and_setup_repo() # Flaskアプリケーションの設定 app = Flask(__name__) # ルートでviews/index.htmlを表示 @app.route('/') def index(): # templates/index.html が存在しない場合は404エラー if not os.path.exists("templates/index.html"): return abort(404, description="views/index.html not found.") # Flaskのrender_templateを使用してindex.htmlを表示 return render_template('index.html') # 静的ファイルを提供するためのルート @app.route('/') def static_files(filename): return send_from_directory('static', filename) # main.jsの存在を確認するエンドポイント @app.route('/check_main_js') def check_main_js(): if os.path.exists('static/main.js'): return "main.js exists." else: return "main.js does not exist." if __name__ == '__main__': # port 7860でFlaskアプリを起動 app.run(host='0.0.0.0', port=7860)