# -*- mode: Python; tab-width: 4; -*
#
# The Texas Twister HTTP Proxy:
#   Using the twisted network library
#
# Author: Jason R. Sumler
# Copyright (c) 2017
#
# Note: To run the service the PYTHONPATH environment
#       varable needs to be set to the modules directory
#
# ENV PYTHONPATH=/home/user/code/TexasTwister/modules
#--------------------------------------------------
"""
          http                       www
        ( ( (                      ( ( (
      ) ) )                       ) ) )
   (~~~~~~~~~)                 (~~~~~~~~~)
    |REACTOR|                   |REACTOR|
    |   1   |                   |   2   |
    I      _._                  I       _._
    I    /'   `\                I     /'   `\
    I   |   N   |               I    |   N   |
    f   |   |~~~~~~~~~~~~~~|    f    |    |~~~~~~~~~~~~~~|
  .'    |   ||~~~~~~~~|    |  .'     |    | |~~~~~~~~|   |
/'______|___||__###___|____|/'_______|____|_|__###___|___|
"""
#--------------------------------------------------


from twisted.internet import reactor

from txTwisterProxy import reactions


def main():
    """
    Bind a TCP listener at port 8080 and
    use the proxy factory to create an instance to handle requests
    """
    reactor.listenTCP(8080, reactions.TexasTwisterProxyFactory())

    # Initalize the reactors!
    reactor.run()

# --------------------------------------------------
if __name__ == '__main__':
    main()
