Skip to content

Commit e2e2e9e

Browse files
mehyedesalexellis
authored andcommitted
Set default value for hostname
This will avoid raising KeyError exceptions when trying to fetch the value of the HOSTNAME env variable on faasd. Signed-off-by: Mehdi Yedes <[email protected]>
1 parent f805dad commit e2e2e9e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

template/python3-http-armhf/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self):
1717

1818
class Context:
1919
def __init__(self):
20-
self.hostname = os.environ['HOSTNAME']
20+
self.hostname = os.getenv('HOSTNAME', 'localhost')
2121

2222
def format_status_code(resp):
2323
if 'statusCode' in resp:
@@ -66,4 +66,4 @@ def call_handler(path):
6666
return resp
6767

6868
if __name__ == '__main__':
69-
serve(app, host='0.0.0.0', port=5000)
69+
serve(app, host='0.0.0.0', port=5000)

template/python3-http/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self):
1717

1818
class Context:
1919
def __init__(self):
20-
self.hostname = os.environ['HOSTNAME']
20+
self.hostname = os.getenv('HOSTNAME', 'localhost')
2121

2222
def format_status_code(resp):
2323
if 'statusCode' in resp:
@@ -66,4 +66,4 @@ def call_handler(path):
6666
return resp
6767

6868
if __name__ == '__main__':
69-
serve(app, host='0.0.0.0', port=5000)
69+
serve(app, host='0.0.0.0', port=5000)

0 commit comments

Comments
 (0)