text: from flask import Flask, render_template, flash, request 
  from wtforms import Form, TextField, TextAreaField, validators, StringField, SubmitField
  from waitress import serve
  import logging, requests, os, json
  
  # App config.
  app = Flask(__name__)
  app.config.from_object(__name__)
  app.config['SECRET_KEY'] = '6d441g27d242f27567d541f2b6176a'
  
  #setup logging
  log = logging.getLogger()
  log.setLevel('INFO')
  handler = logging.StreamHandler()
  handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s"))
  log.addHandler(handler)
  
  class ReusableForm(Form):
      longUrl = TextField('Enter the URL you would like shortened:', validators=[validators.required()])
  
      @app.route("/", methods=['GET', 'POST'])
      def hello():
          form = ReusableForm(request.form)
  
          log.info('form errors: ' + str(form.errors))
          if request.method == 'POST':
              longUrl = request.form['longUrl']
              log.info('longUrl: ' + longUrl)
              request_json = json.dumps({'longUrl': longUrl})
              log.info('request_json: ' + request_json)
              endpointName = 'createShortUrl'
              scheme = 'http://'
              urlWithoutEndpoint = scheme + os.getenv('APPSERVER_HOST') + ':' + os.getenv('APPSERVER_PORT')
              url_response = requests.post(urlWithoutEndpoint + '/' + endpointName, data=None, json=request_json)
              json_response = json.loads(url_response.content)
              #TODO: this doesn't work with "appserver" on a browser, because that doesn't resolve outside the container.             # We need the actual hostname, for now, we're hardcoding localhost -- we need to have an INTERNAL_APPSERVER_HOST/PORT and an EXTERNAL_APPSERVER_HOST/PORT so that we can use them properly
              shortUrl = scheme + "localhost" + ':' + os.getenv('APPSERVER_PORT') + '/' + json_response['shortUrl']
              log.info('shortUrl: ' + shortUrl)
  
          if form.validate() and len(shortUrl) > 0:
              flash(shortUrl)
  
          return render_template('hello.html', form=form)
  
  if __name__ == "__main__":
      log.info('starting ui')
      serve(app, host='0.0.0.0', port=5000)
  