Ejemplo n.º 1
0
def build_route():
    router=RouteMatcher()

    cfg = vertx.config()
    config=JsonObject(cfg).getObject("router")

    for route in config.getArray("routes"):
        controller_description = route.getString("controller")



        def controller_name(): return str(controller_description).split(".")[0]

        if not route.getString("get") is None:
            print("get:"+str(route))
            router.get( route.getString("get"),controller_renderer(config.getString("controller-path"),controller_name(),route.getString("view"),renderer(route,controller_description),cfg["session-dir"]))
        elif not route.getString("post") is None:
            print("post:"+str(route))
            router.post( route.getString("post"),controller_renderer(config.getString("controller-path"),controller_name(),route.getString("view"),renderer(route,controller_description),cfg["session-dir"]))
        elif not route.getString("static") is None:
            print("static:"+str(route))
            router.get(route.getString("static"),static_files_renderer(route.getString("folder")) )
    return router
Ejemplo n.º 2
0
import vertx
from core.http import RouteMatcher

server = vertx.create_http_server()

route_matcher = RouteMatcher()

def getUser(req): 
	# read parameter from URI
	userid = req.params['userid']
	req.response.end('You requested user information '+userid)

def addUser(req):
	userid = req.params['userid']
	# read body
	@req.data_handler
	def data_handler(buffer):
		req.response.end('i received body :'+str(buffer))
		print(buffer)
route_matcher.post('/user/:userid',addUser)
	
server.request_handler(route_matcher).listen(8080,'localhost')
Ejemplo n.º 3
0
    else:
        #req.response.put_header('Expect', '404-Continue')
        req.response.status_code = 404
        req.response.end()

def file_info(req):
    def props_handler(err, props):
        if err:
            logger.error("Failed to retrieve file props: %s"% err)
        else:
            logger.info('File props are:')
            logger.info("Last accessed: %s"% props.symbolic_link)
            req.response.status_code = 200
            #req.response.status_message = props.symbolic_link
            
    name = "%s%s"% (path_symlink,req.params['filename'])
    logger.info(name)
    #fs.props(name, props_handler)

route_matcher.post('/upload', upload.upload_handler)
route_matcher.get('/dl/:uid/:filename', file_service.file_handler)
route_matcher.get('/', index_handler)

#set server
#server.set_send_buffer_size(4 * 1024)
#server.set_receive_buffer_size(100 * 1024)
#logger.info("send buffer: %s"% server.send_buffer_size)
#logger.info("receive buffer: %s"% server.receive_buffer_size)
#logger.info(server.use_pooled_buffers)
server.request_handler(route_matcher).listen(app_config['port'], app_config['host'])