/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.gateway.handler;

import com.crunii.micro.common.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

import static org.springframework.http.MediaType.APPLICATION_JSON;

/**
 * @author 田平 create 2019年12月3日下午3:45:07
 */
@Component
public class RoutesDetailHandler {

	@Autowired
	private RouteLocator routeLocator;

	public Mono<ServerResponse> routes(ServerRequest request) {
		Mono<List<String>> listMono = routeLocator.getRoutes().map(r -> r.toString()).collectList();
		return ServerResponse.ok()
				.contentType(APPLICATION_JSON)
				.body(listMono, Route.class);
	}

}
