Beispiel #1
0
    def _start(self, server):
        if settings.MULTI_PROCESS:
            server.bind(options.port)
            server.start(self.process_num)
            for advanced_port in settings.ADVANCED_SERVER_PORT:
                # bind more port if set
                tornado.process.fork_processes(self.process_num)
                sockets = bind_sockets(advanced_port)
                server.add_sockets(sockets)
        else:
            server.listen(options.port)

        self.initialize()
        IOLoop.instance().start()
Beispiel #2
0
    logging.basicConfig(filename=APP_LOG_FILENAME,
                        filemode='a',
                        format='%(asctime)s,%(msecs)-3d - %(name)-12s - %(levelname)-8s => %(message)s',
                        datefmt='%Y-%m-%d %H:%M:%S',
                        level=log_level)
    logging.info("API Employee started")

    if args.no_ssl:
        server_port = server_config['HttpPort']
        server_protocol = 'http'
        ssl_config = None
    else:
        server_port = server_config['HttpsPort']
        server_protocol = 'https'
        ssl_config = (server_config['TLSCertLocation'], server_config['TLSKeyLocation'])
    print("API service is starting and will be avaialble at '{}://localhost:{}/.\nThe application log is stored in the file '{}'.".format(server_protocol, server_port, APP_LOG_FILENAME))

    # configuring and starting the web server
    # app.run(debug=args.debug, host='0.0.0.0', port=server_port, threaded=True, ssl_context=ssl_config)
    api_root = resource.Resource()
    api_root.putChild(b"servidores", Employees())
    api_root.putChild(b"servidor", EmployeeRoot())
    root = resource.Resource()
    root.putChild(b"api", api_root)

    site = server.Site(root)
    endpoint_spec = "tcp:{}".format(server_port)
    server = endpoints.serverFromString(reactor, endpoint_spec)
    server.listen(site)
    reactor.run()
Beispiel #3
0
    """Serve all book ids.
    """
    def render_GET(self, request):
        return json.dumps(list(BOOKS.keys())).encode("utf8")


class Book(Resource):
    """Return detailed data about each book.
    """
    isLeaf = True

    def render_GET(self, request):
        book_id = request.args.get(b"id")
        book = BOOKS.get(book_id[0].decode("utf8"))
        if not book:
            request.setResponseCode(404)
            return b""
        return json.dumps(book).encode("utf8")


if __name__ == "__main__":
    log.startLogging(sys.stdout)
    root = Resource()
    root.putChild(b"", Index())
    root.putChild(b"book", Book())
    site = server.Site(root)
    endpoint_spec = "ssl:port=8080:privateKey=privkey.pem:certKey=cert.pem"
    server = endpoints.serverFromString(reactor, endpoint_spec)
    server.listen(site)
    reactor.run()