Spring Cloud Gateway CORS 发表于 2018-11-08 | 分类于 Spring Boot , ApiGateway JavaKotlin12345678910111213141516171819202122232425262728293031@Configurationclass RouteConfiguration { @Bean fun allowCORS(): WebFilter { return WebFilter { webExchange, chains -> val request = webExchange.request val requestHeaders = request.headers val response = webExchange.response val respHeaders = response.headers respHeaders.add(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, "*") respHeaders.add(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "*") respHeaders.add(HttpHeaders.ACCESS_CONTROL_MAX_AGE, MAX_AGE) respHeaders.addAll(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, requestHeaders.accessControlRequestHeaders) respHeaders.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, "*") respHeaders.add(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true") if (request.method == HttpMethod.OPTIONS) { response.statusCode = HttpStatus.OK Mono.empty() } else { chains.filter(webExchange) } } } companion object { const val MAX_AGE = "18000L" }} Refer http://springcloud.cn/view/343