I've 2 services the first one for serves html files the second one for serves rest calls, I'd like merge them together to use an unique service
--- first service
#!/usr/bin/env python3
from http.server import CGIHTTPRequestHandler, HTTPServer
handler = CGIHTTPRequestHandler
server = HTTPServer(('localhost', 8123), handler)
server.serve_forever()
--- second service
#!/usr/bin/env python
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import json
import cgi
import tempfile
import os
import subprocess
from subprocess import Popen
class Server(BaseHTTPRequestHandler):
def _set_headers(self):
self.send_response(200)
self.send_header('Content-type', 'application/text')
self.end_headers()
# GET sends back a Hello world message
def do_GET(self):
self._set_headers()
self.wfile.write(json.dumps({'hello': 'world', 'received': 'ok'}))
# POST echoes the message adding a JSON field
# ...
def run(server_class=HTTPServer, handler_class=Server, port=8080):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print 'Starting httpd on port %d...' % port
httpd.serve_forever()
if __name__ == "__main__":
from sys import argv
run()
Aucun commentaire:
Enregistrer un commentaire