Commit 8159e9a4 authored by Łukasz Nowak's avatar Łukasz Nowak

Simple python backend

parent 55d92252
import BaseHTTPServer
import sys
import socket
class HTTP6Server(BaseHTTPServer.HTTPServer):
address_family = socket.AF_INET6
class BackendHandler(BaseHTTPServer.BaseHTTPRequestHandler):
response = 'ThisIsResponse' * 10
content_security_policy = """"default-src 'none'; img-src 'self' data:; """ \
"""media-src 'self'; connect-src 'self' %s; script-src 'self' """ \
"""'unsafe-eval'; font-src netdna.bootstrapcdn.com; style-src """ \
"""'self' netdna.bootstrapcdn.com 'unsafe-inline' data:; frame-src """ \
"""'self' data:"""
def do_GET(self):
self.send_response(200)
self.send_header('X-Frame-Options', 'SAMEORIGIN')
self.send_header('X-Content-Type-Options', 'nosniff')
self.send_header(
'Content-Security-Policy',
self.content_security_policy % (self.server.CORS_DOMAIN,))
self.send_header('Access-Control-Allow-Origin', self.server.CORS_ORIGIN)
self.end_headers()
if self.path == '/test':
self.wfile.write(self.response)
else:
self.wfile.write('Hello!')
def show_help():
print 'Invoke: %s ip port domain host' % (sys.argv[0])
if __name__ == '__main__':
if len(sys.argv) != 5:
show_help()
sys.exit(1)
ip, port, domain, host = sys.argv[1:]
if ':' in ip:
ip_ = '[%s]' % (ip,)
server = HTTP6Server
else:
ip_ = ip
server = BaseHTTPServer.HTTPServer
print 'Serving on http://%s:%s/ with allowed domain %s on host %s' % (
ip_, port, domain, host)
server = server(
(ip, int(port)),
BackendHandler)
server.CORS_DOMAIN = domain
server.CORS_ORIGIN = host
server.serve_forever()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment