Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] 支持自定义端口号和监听IP #32

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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后端的安装

#### 安装依赖
Expand Down
3 changes: 0 additions & 3 deletions backend/.flaskenv_template
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 8 additions & 1 deletion backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
port:
backend: 5008
frontend: 3000
host:
backend: 0.0.0.0
frontend: 0.0.0.0
1 change: 1 addition & 0 deletions frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VUE_APP_BACKEND_PORT = 5008
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/global.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
const BASEURL = "http://127.0.0.1:5008/"
const BASEURL = "http://"+process.env.VUE_APP_BACKEND_IP+":"+process.env.VUE_APP_BACKEND_PORT+"/"
export default {
BASEURL,
};
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ import 'element-plus/theme-chalk/display.css'
import JSZIP from "jszip"
import zhCn from 'element-plus/es/locale/lang/zh-cn'



createApp(App).use(router).use(ElementPlus,{locale: zhCn}).use(JSZIP).mount('#app')
8 changes: 7 additions & 1 deletion frontend/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const { defineConfig } = require('@vue/cli-service')
const YAML = require('yaml')
const fs = require("fs");
const file = fs.readFileSync('../config.yaml', 'utf8')
config = YAML.parse(file)

module.exports = defineConfig({
transpileDependencies: true,
devServer: {
port: 3000, // 端口
host: config["host"]["frontend"],
port: config["port"]["frontend"], // 端口
},

// transpileDependencies: ['@arcgis']
Expand Down