Skip to content

Commit 0195cfc

Browse files
committed
Need to bind localhost explicitly for gunicorn
Without an explicit bind it seems to only bind to the 127.0.0.1 IP. To support using CLI options with gunicorn the application cannot also parse the options. Instead only use optparse when running stand-alone.
1 parent e909410 commit 0195cfc

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Next, start the server. You can do this in either debugging mode (where `debug=T
2929

3030
```
3131
python3 app.py --debug (debug mode)
32-
gunicorn app:app (production mode)
32+
gunicorn --bind localhost:8080 app:app (production mode)
3333
```
3434

3535
You can view your running local application at this URL:

app.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
import json
22
import traceback
33
from collections import OrderedDict
4-
from optparse import OptionParser
54

65
import mf2py
76
import mf2util
87
from flask import Flask, jsonify, make_response, render_template, request
98

10-
parser = OptionParser()
11-
12-
parser.add_option(
13-
"-d",
14-
"--debug",
15-
action="store_true",
16-
default=False,
17-
help="Run application in debug mode",
18-
)
19-
20-
(options, args) = parser.parse_args()
21-
229
app = Flask(__name__)
2310

2411
mf2py.Parser.user_agent = "python.microformats.io (mf2py/" + mf2py.__version__ + ") Mozilla/5.0 Chrome/29.0.1547.57 Safari/537.36"
@@ -68,6 +55,18 @@ def fetch_mf2(url):
6855
traceback.print_exc()
6956
return jsonify(error="%s: %s" % (type(e).__name__, e)), 400
7057

58+
if __name__ == "__main__":
59+
from optparse import OptionParser
60+
61+
parser = OptionParser()
62+
parser.add_option(
63+
"-d",
64+
"--debug",
65+
action="store_true",
66+
default=False,
67+
help="Run application in debug mode",
68+
)
69+
(options, args) = parser.parse_args()
7170

72-
if options.debug:
73-
app.run(debug=True, port=8080)
71+
if options.debug:
72+
app.run(debug=True, port=8080)

0 commit comments

Comments
 (0)