diff --git a/README.md b/README.md index 3a0446e..867a50e 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,18 @@ pip install -r requirements.txt python setup.py install ``` +### 修改端口号(可选) + +按以下规则编辑根目录下的`config.yaml`文件。 +``` yaml +port: + backend: 后端端口号 + frontend: 前端端口号 +host: + backend: 后端监听ip + frontend: 前端监听ip +``` + ### Web后端的安装 #### 安装依赖 diff --git a/backend/.flaskenv_template b/backend/.flaskenv_template index eb53755..6a82f73 100644 --- a/backend/.flaskenv_template +++ b/backend/.flaskenv_template @@ -1,9 +1,6 @@ # flask配置 FLASK_APP=app.py -FLASK_ENV=development FLASK_DEBUG=1 -FLASK_RUN_HOST = 127.0.0.1 -FLASK_RUN_PORT = 5008 #flask配置 SYSTEM_NAME=Hippo diff --git a/backend/app.py b/backend/app.py index d7e3dbe..fd0396c 100644 --- a/backend/app.py +++ b/backend/app.py @@ -18,4 +18,11 @@ def before(): migrate = Migrate(app, db) if __name__ == '__main__': - app.run(host='0.0.0.0', port="5008") + import yaml + with open('../config.yaml') as file: + config = yaml.load(file.read(), Loader=yaml.FullLoader) + with open("../frontend/.env", 'w') as file: + file.write("VUE_APP_BACKEND_PORT = {}\nVUE_APP_BACKEND_IP = {}".format( + config["port"]["backend"], config["host"]["backend"] + if config["host"]["backend"] != "0.0.0.0" else "127.0.0.1")) + app.run(host=config["host"]["backend"], port=config["port"]["backend"]) diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..29d26ab --- /dev/null +++ b/config.yaml @@ -0,0 +1,6 @@ +port: + backend: 5008 + frontend: 3000 +host: + backend: 0.0.0.0 + frontend: 0.0.0.0 \ No newline at end of file diff --git a/frontend/.env b/frontend/.env new file mode 100644 index 0000000..6be297e --- /dev/null +++ b/frontend/.env @@ -0,0 +1 @@ +VUE_APP_BACKEND_PORT = 5008 \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json index f96f4df..bc16ba3 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -20,7 +20,8 @@ "vue-cropper": "^1.0.3", "vue-keep-scroll-position": "^0.1.2", "vue-popperjs": "^2.3.0", - "vue-router": "^4.0.3" + "vue-router": "^4.0.3", + "yaml": "^2.1.3" }, "devDependencies": { "@vue/cli-plugin-babel": "~5.0.0", diff --git a/frontend/src/global.vue b/frontend/src/global.vue index 98ac116..03c96f7 100644 --- a/frontend/src/global.vue +++ b/frontend/src/global.vue @@ -1,5 +1,5 @@