diff --git a/README.md b/README.md index ed83db3..c5b32c3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ https://github.com/MollardMichael/python-reverse-proxy/tree/master https://github.com/ItsEcholot/ContainerNursery - +https://gist.github.com/bsergean/bad452fa543ec7df6b7fd496696b2cd8 +https://docker-py.readthedocs.io/en/stable/ Docker Stack Setup ```yaml diff --git a/app.py b/app.py index a800558..87ce35a 100644 --- a/app.py +++ b/app.py @@ -47,26 +47,25 @@ class ProxyHandler(http.server.BaseHTTPRequestHandler): if (starting == True): self.send_response(201) + self.send_header('Content-Type', 'text/plain') + self.send_header('refresh', proxy_host_configuration['proxy_timeout_seconds']) self.end_headers() - self.wfile.write(str.encode("starting container: {0}".format(container['container_name']))) - conn.close() - + self.wfile.write(bytes("starting container: {0} waiting for {1}s".format(container['container_name'], proxy_host_configuration['proxy_timeout_seconds']),"utf-8")) + return + # Open a connection to the target server conn = http.client.HTTPConnection(proxy_host_configuration['proxy_host'], proxy_host_configuration['proxy_port']) conn.request(method, self.path, headers=self.headers) response = conn.getresponse() - #print(response.status) self.send_response(response.status) - #self.send_header('host', proxy_host_configuration['container_name']) + + self.send_header('host', proxy_host_configuration['proxy_host']) for header, value in response.getheaders(): self.send_header(header, value) self.end_headers() - - if (response.status != 301): - self.wfile.write(response.getcode()) - + self.wfile.write(response.read()) conn.close() class ThreadedHTTPServer(ThreadingMixIn, http.server.HTTPServer): @@ -82,5 +81,5 @@ if __name__ == '__main__': server_address = ('', configuration['proxy_port']) proxy_handler = ProxyHandler(configuration, docker_client) httpd = ThreadedHTTPServer(server_address, proxy_handler) - print('Reverse proxy server running on port 8888...') + print('Reverse proxy server running on port {0}...'.format(configuration['proxy_port'])) httpd.serve_forever() \ No newline at end of file diff --git a/config.yml b/config.yml index 1b08a56..84bbb45 100644 --- a/config.yml +++ b/config.yml @@ -5,4 +5,5 @@ proxy_hosts: - container_name: wp-dev-db-1 - container_name: wp-dev-wordpress-1 proxy_host: localhost - proxy_port: 80 \ No newline at end of file + proxy_port: 80 + proxy_timeout_seconds: 10 \ No newline at end of file