Skip to content

Commit

Permalink
Add CORS setting (#164)
Browse files Browse the repository at this point in the history
* add cors setting

* revert line feed code
  • Loading branch information
Risenafis committed Jun 10, 2024
1 parent 001652b commit c78c914
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from flask_apscheduler import APScheduler
from flask_login import LoginManager
from flask_wtf import CSRFProtect
from flask_cors import CORS

from utils.data_utils import clean_folder, check_is_none
from utils.phrases_dict import phrases_dict_init
Expand All @@ -28,6 +29,8 @@
# 禁用tts api请求的CSRF防护
csrf.exempt(voice_api)

CORS(app, resources={r"/voice/*": {"origins": config.http_service.origins}})

if config.system.is_admin_enabled:
login_manager = LoginManager()
login_manager.init_app(app)
Expand Down
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ class HttpService(AsDictMixin):
host: str = "0.0.0.0"
port: int = 23456
debug: bool = False
origins: str = "*"


@dataclass
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pydantic==2.3.0
werkzeug==2.3.6
flask_login
flask_wtf
flask-cors
ngrok

# Compression and Decompression
Expand Down
4 changes: 4 additions & 0 deletions tts_app/templates/pages/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
<span class="input-group-text">port</span>
<input class="form-control" type="password" id="port">
</div>
<div class="input-group mb-3 item">
<span class="input-group-text">allow origins</span>
<input class="form-control" type="text" id="origins">
</div>

</div>
</div>
Expand Down

0 comments on commit c78c914

Please sign in to comment.