Replace HTTP server implementation with Flask API for DNS updates

This commit is contained in:
2025-12-27 10:22:26 +01:00
parent b78c848525
commit 2db1671d8a
2 changed files with 12 additions and 29 deletions

12
app.py Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env python3
from flask import Flask
app = Flask('dns-updater')
@app.route('/api/dnsupdate')
def api_root():
return "Welcome to the DNS Updater API"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)

View File

@@ -1,29 +0,0 @@
#!/usr/bin/env python3
import http.server
import argparse
class DNSUpdateHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(b'DNS Update Service is running.\n')
def run(server_class=http.server.HTTPServer, handler_class=DNSUpdateHandler, address='127.0.0.1', port=8080):
server_address = (address, port)
httpd = server_class(server_address, handler_class)
print(f'Starting DNS Update Service on {address}:{port}...')
httpd.serve_forever()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Run the DNS Update Service.')
parser.add_argument('--port', type=int, default=8080, help='Port to run the server on')
parser.add_argument('--address', type=str, default='127.0.0.1', help='IP address to listen on (not used in this simple example)')
args = parser.parse_args()
try:
run(address=args.address, port=args.port)
except KeyboardInterrupt:
print("\nShutting down DNS Update Service.")