import http.server

PORT = 8000
HOST = "127.0.0.1"

# This will display the site at `http://localhost:8000/`
server_address = (HOST, PORT)

# The CGIHTTPRequestHandler class allows us to run the cgi script in /cgi-bin/
# Rather than attempt to display the cgi file itself, which a 'BaseHTTPRequestHandler' or
# 'SimpleHTTPRequestHandler' may do
httpd = http.server.HTTPServer(server_address, http.server.CGIHTTPRequestHandler)
print("Starting my web server on port {0}".format(PORT))
# Make sure the server is always serving the content
# You can stop the server running using CTRL + C
httpd.serve_forever()

import os
import http.server

PORT = int(os.environ.get("PORT", 8000))
HOST = "127.0.0.1"

# This will display the site at `http://localhost:8000/`
server_address = (HOST, PORT)

# The CGIHTTPRequestHandler class allows us to run the cgi script in /cgi-bin/
# Rather than attempt to display the cgi file itself, which a 'BaseHTTPRequestHandler' or
# 'SimpleHTTPRequestHandler' may do
httpd = http.server.HTTPServer(server_address, http.server.CGIHTTPRequestHandler)
print("Starting my web server on port {0}".format(PORT))
# Make sure the server is always serving the content
# You can stop the server running using CTRL + C
httpd.serve_forever()

Set port depending on environment
Set port depending on environment

+ import os
  import http.server
  
- PORT = 8000
+ PORT = int(os.environ.get("PORT", 8000))
  HOST = "127.0.0.1"
  
  # This will display the site at `http://localhost:8000/`
  server_address = (HOST, PORT)
  
  # The CGIHTTPRequestHandler class allows us to run the cgi script in /cgi-bin/
  # Rather than attempt to display the cgi file itself, which a 'BaseHTTPRequestHandler' or
  # 'SimpleHTTPRequestHandler' may do
  httpd = http.server.HTTPServer(server_address, http.server.CGIHTTPRequestHandler)
  print("Starting my web server on port {0}".format(PORT))
  # Make sure the server is always serving the content
  # You can stop the server running using CTRL + C
  httpd.serve_forever()
  
Set port depending on environment
## Code Before:
import http.server

PORT = 8000
HOST = "127.0.0.1"

# This will display the site at `http://localhost:8000/`
server_address = (HOST, PORT)

# The CGIHTTPRequestHandler class allows us to run the cgi script in /cgi-bin/
# Rather than attempt to display the cgi file itself, which a 'BaseHTTPRequestHandler' or
# 'SimpleHTTPRequestHandler' may do
httpd = http.server.HTTPServer(server_address, http.server.CGIHTTPRequestHandler)
print("Starting my web server on port {0}".format(PORT))
# Make sure the server is always serving the content
# You can stop the server running using CTRL + C
httpd.serve_forever()

## Instruction:
Set port depending on environment
## Code After:
import os
import http.server

PORT = int(os.environ.get("PORT", 8000))
HOST = "127.0.0.1"

# This will display the site at `http://localhost:8000/`
server_address = (HOST, PORT)

# The CGIHTTPRequestHandler class allows us to run the cgi script in /cgi-bin/
# Rather than attempt to display the cgi file itself, which a 'BaseHTTPRequestHandler' or
# 'SimpleHTTPRequestHandler' may do
httpd = http.server.HTTPServer(server_address, http.server.CGIHTTPRequestHandler)
print("Starting my web server on port {0}".format(PORT))
# Make sure the server is always serving the content
# You can stop the server running using CTRL + C
httpd.serve_forever()
