0

Is it possible to create a dummy server name in Flask during production? For example I want the following: www.foo.com for the development.

def main():
    app.run(debug=True, host='foo.com', port=8000)

such that routes like:

@app.route('/bar/')
def bar() -> str:
    return 'bar'

would be reached at foo.com/bar/. I've tried changing the configuration:

app.config['SERVER_NAME'] = 'foo.com'

but I get an OSError: [Errno 49] Can't assign requested address

ajrlewis
  • 2,968
  • 3
  • 33
  • 67

2 Answers2

0

change host parameter

app.run(debug=True, host='0.0.0.0', port=8000)

It defines the ip addresses the server will listen on, not the DNS. See link for more explanation.

ofirule
  • 4,233
  • 2
  • 26
  • 40
0

Add an entry for foo.com pointing to the local IP (127.0.0.1) in your development PC hosts file. For example, on Windows the hosts file is called hosts and is located at C:\Windows\System32\drivers\etc for a standard installation.

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host


127.0.0.1 foo.com

You will then be able to server up your Flask pages on foo.com:8000 when developing.

pjcunningham
  • 7,676
  • 1
  • 36
  • 49