Skip to content

Commit ed4dcfc

Browse files
committed
chore: add local start for example
1 parent 744ccd0 commit ed4dcfc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

example/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Flask example
2+
3+
本地启动服务:
4+
5+
```bash
6+
$ ENV=local python app.py
7+
```
8+
9+
可以发现 `app.py` 中通过判断环境变量 `ENV``local` 才启动服务,云函数运行时就不会启动服务。

example/app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from flask import Flask, jsonify
23
app = Flask(__name__)
34

@@ -16,3 +17,7 @@ def users():
1617
@app.route("/users/<id>")
1718
def user(id):
1819
return jsonify(data={'name': 'test1'})
20+
21+
isLocal = os.getenv('ENV') == 'local'
22+
if isLocal:
23+
app.run(host='0.0.0.0',port=3000,debug=True)

0 commit comments

Comments
 (0)