Exemple #1
0
def start ():
	global web_cerver
	global job_queue

	web_cerver = cerver.cerver_create_web (
		"web-cerver".encode ('utf-8'), 8080, 10
	)

	# main configuration
	cerver.cerver_set_receive_buffer_size (web_cerver, 4096);
	cerver.cerver_set_thpool_n_threads (web_cerver, 4);
	cerver.cerver_set_handler_type (web_cerver, cerver.CERVER_HANDLER_TYPE_THREADS);

	cerver.cerver_set_reusable_address_flags (web_cerver, True);

	# HTTP configuration
	http_cerver = cerver.http_cerver_get (web_cerver)

	# GET /
	main_route = cerver.http_route_create (cerver.REQUEST_METHOD_GET, "/".encode ('utf-8'), main_handler)
	cerver.http_cerver_route_register (http_cerver, main_route)

	# POST /jobs
	jobs_route = cerver.http_route_create (cerver.REQUEST_METHOD_POST, "jobs".encode ('utf-8'), jobs_handler)
	cerver.http_route_set_modifier (jobs_route, cerver.HTTP_ROUTE_MODIFIER_MULTI_PART)
	cerver.http_cerver_route_register (http_cerver, jobs_route)

	# job queue
	job_queue = cerver.threads.job_queue_create (cerver.threads.JOB_QUEUE_TYPE_HANDLERS)
	cerver.threads.job_queue_set_handler (job_queue, custom_handler_method)
	cerver.threads.job_queue_start (job_queue)

	# start
	cerver.cerver_start (web_cerver)
Exemple #2
0
def start():
    global web_cerver
    web_cerver = cerver.cerver_create_web("web-cerver".encode('utf-8'), 8080,
                                          10)

    # main configuration
    cerver.cerver_set_receive_buffer_size(web_cerver, 4096)
    cerver.cerver_set_thpool_n_threads(web_cerver, 4)
    cerver.cerver_set_handler_type(web_cerver,
                                   cerver.CERVER_HANDLER_TYPE_THREADS)

    cerver.cerver_set_reusable_address_flags(web_cerver, True)

    # HTTP configuration
    http_cerver = cerver.http_cerver_get(web_cerver)

    cerver.http_cerver_set_uploads_path(http_cerver, "uploads".encode('utf-8'))

    # GET /test
    test_route = cerver.http_route_create(cerver.REQUEST_METHOD_GET,
                                          "test".encode('utf-8'), test_handler)
    cerver.http_cerver_route_register(http_cerver, test_route)

    # POST /upload
    upload_route = cerver.http_route_create(cerver.REQUEST_METHOD_POST,
                                            "upload".encode('utf-8'),
                                            upload_handler)
    cerver.http_route_set_modifier(upload_route,
                                   cerver.HTTP_ROUTE_MODIFIER_MULTI_PART)
    cerver.http_cerver_route_register(http_cerver, upload_route)

    # start
    cerver.cerver_start(web_cerver)
Exemple #3
0
def start():
    global api_cerver
    api_cerver = cerver.cerver_create_web("api-cerver".encode('utf-8'), 8080,
                                          10)

    # main configuration
    cerver.cerver_set_receive_buffer_size(api_cerver, 4096)
    cerver.cerver_set_thpool_n_threads(api_cerver, 4)
    cerver.cerver_set_handler_type(api_cerver,
                                   cerver.CERVER_HANDLER_TYPE_THREADS)

    cerver.cerver_set_reusable_address_flags(api_cerver, True)

    # HTTP configuration
    http_cerver = cerver.http_cerver_get(api_cerver)

    cerver.http_cerver_auth_set_jwt_algorithm(http_cerver,
                                              cerver.JWT_ALG_RS256)
    cerver.http_cerver_auth_set_jwt_priv_key_filename(
        http_cerver, "keys/key.key".encode('utf-8'))
    cerver.http_cerver_auth_set_jwt_pub_key_filename(
        http_cerver, "keys/key.pub".encode('utf-8'))

    # GET /api/users
    users_route = cerver.http_route_create(cerver.REQUEST_METHOD_GET,
                                           "api/users".encode('utf-8'),
                                           main_users_handler)
    cerver.http_cerver_route_register(http_cerver, users_route)

    # POST api/users/register
    users_register_route = cerver.http_route_create(cerver.REQUEST_METHOD_POST,
                                                    "register".encode('utf-8'),
                                                    users_register_handler)
    cerver.http_route_child_add(users_route, users_register_route)

    # POST api/users/login
    users_login_route = cerver.http_route_create(cerver.REQUEST_METHOD_POST,
                                                 "login".encode('utf-8'),
                                                 users_login_handler)
    cerver.http_route_child_add(users_route, users_login_route)

    # GET api/users/profile
    users_profile_route = cerver.http_route_create(cerver.REQUEST_METHOD_GET,
                                                   "profile".encode('utf-8'),
                                                   users_profile_handler)
    cerver.http_route_set_auth(users_profile_route,
                               cerver.HTTP_ROUTE_AUTH_TYPE_BEARER)
    cerver.http_route_set_decode_data_into_json(users_profile_route)
    cerver.http_route_child_add(users_route, users_profile_route)

    # start
    cerver.cerver_start(api_cerver)
Exemple #4
0
def start ():
	global web_cerver
	web_cerver = cerver.cerver_create_web (
		"web-cerver".encode ('utf-8'), 8080, 10
	)

	# main configuration
	cerver.cerver_set_receive_buffer_size (web_cerver, 4096);
	cerver.cerver_set_thpool_n_threads (web_cerver, 4);
	cerver.cerver_set_handler_type (web_cerver, cerver.CERVER_HANDLER_TYPE_THREADS);

	cerver.cerver_set_reusable_address_flags (web_cerver, True);

	# HTTP configuration
	http_cerver = cerver.http_cerver_get (web_cerver)

	cerver.http_cerver_static_path_add (http_cerver, "./public".encode ('utf-8'))

	# GET /
	main_route = cerver.http_route_create (cerver.REQUEST_METHOD_GET, "/".encode ('utf-8'), main_handler)
	cerver.http_cerver_route_register (http_cerver, main_route)

	# GET /test
	test_route = cerver.http_route_create (cerver.REQUEST_METHOD_GET, "test".encode ('utf-8'), test_handler)
	cerver.http_cerver_route_register (http_cerver, test_route)

	# GET /text
	text_route = cerver.http_route_create (cerver.REQUEST_METHOD_GET, "text".encode ('utf-8'), text_handler)
	cerver.http_cerver_route_register (http_cerver, text_route)

	# GET /json
	json_route = cerver.http_route_create (cerver.REQUEST_METHOD_GET, "json".encode ('utf-8'), json_handler)
	cerver.http_cerver_route_register (http_cerver, json_route)

	# GET /hola
	hola_route = cerver.http_route_create (cerver.REQUEST_METHOD_GET, "hola".encode ('utf-8'), hola_handler)
	cerver.http_cerver_route_register (http_cerver, hola_route)

	# GET /adios
	adios_route = cerver.http_route_create (cerver.REQUEST_METHOD_GET, "adios".encode ('utf-8'), adios_handler)
	cerver.http_cerver_route_register (http_cerver, adios_route)

	# GET /key
	key_route = cerver.http_route_create (cerver.REQUEST_METHOD_GET, "key".encode ('utf-8'), key_handler)
	cerver.http_cerver_route_register (http_cerver, key_route)

	# start
	cerver.cerver_start (web_cerver)
Exemple #5
0
def end (signum, frame):
	# cerver.cerver_stats_print (web_cerver, False, False)
	cerver.http_cerver_all_stats_print (cerver.http_cerver_get (web_cerver))
	cerver.cerver_teardown (web_cerver)
	cerver.cerver_end ()
	sys.exit ("Done!")