Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add "ignore path" option, to exclude path from routing #1266

Open
mygordienko opened this issue Aug 26, 2019 · 9 comments
Open

Add "ignore path" option, to exclude path from routing #1266

mygordienko opened this issue Aug 26, 2019 · 9 comments

Comments

@mygordienko
Copy link

Enhancement

Currently I see no way I can exclude particular path from routing. For instance if I want my gateway to expose some endpoints.

If I have the following route configuration (/** - matches everything):

- id: frontend
  uri: ${com.siemens.cms.gateway.routes.frontend}
  predicates:
   - Path=/**

I want to be able to do something like the following (make some exclusions):

- id: frontend
  uri: ${com.siemens.cms.gateway.routes.frontend}
  redicates:
  - Path=/**, except: /actuator/**

or

spring:
  cloud:
    gateway:
      routes:
      .....
      ignore:
          predicate:
         - Path=/actuator/**

I think it would be very convenient to have such option.

@mygordienko
Copy link
Author

Are there any updates on this? Is it possible to add such feature?

@bratwurzt
Copy link

This was explained in #496 (comment)

@gberche-orange
Copy link
Contributor

Isn't this issue (#1266) a duplicate of a feature request #309 identified for long time ?

@s-aliasgar
Copy link

Any update on this?

@sfariaNG
Copy link

sfariaNG commented Jul 8, 2022

This was explained in #496 (comment)

The use case OP presented is not addressed by that comment. The presented solution of no://op only means to stop routing and return an HTTP Status code, but it doesn't allow the gateway to handle the request via other means (e.g. local to the gateway).

One way I found to handle this case required using the fluent API since negate doesn't seem to be supported in java config unfortunately. It means removing it from the other routes in application.yml, but I was ok with that for this special purpose route. With this configured the LOGOUT_HTML and LOGOUT_CSS paths are served from the static files on the classpath while all other unmatched paths proxy to the defaultHost.

@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
    return builder.routes()
            .route("default", r -> r
                .order(Ordered.LOWEST_PRECEDENCE)
                .path("/**")
                .and().not(p -> p.path(LOGOUT_HTML, LOGOUT_CSS))
                .filters(f -> f
                    # Any appropriate filters
                )
                .uri(defaultHost)
            )
            .build();
}

@chen-junl
Copy link

how about now?

@sfussenegger
Copy link

sfussenegger commented Apr 26, 2023

Is there any update to this?

I guess a simple NotPath predicate could do the trick:

@Component
public class NotPathRoutePredicateFactory extends PathRoutePredicateFactory {

	@Override
	public Predicate<ServerWebExchange> apply(final Config config) {
		return super.apply(config).negate();
	}

}

usage

- id: frontend
  uri: ${com.siemens.cms.gateway.routes.frontend}
  predicates:
   - Path=/**
   - NotPath=/actuator/**

not particularly pretty though

@boal
Copy link

boal commented Sep 26, 2024

Are there plans to implement the feature?

@spencergibb
Copy link
Member

spencergibb commented Sep 27, 2024

There are no immediate plans to implement this. Watch for if it gets added to a project or milestone

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests