pippo-java / pippo

Micro Java Web Framework
http://www.pippo.ro
Apache License 2.0
787 stars 128 forks source link

Add resource route helper in router #619

Closed decebals closed 1 year ago

decebals commented 1 year ago

With this very simple modification I can extract the part with routes from Application in custom Router. See below an example using Spring IoC:

@Component
public class MyRouter extends DefaultRouter {

    @Autowired
    private List<RouteGroup> routeGroups;

    @Autowired
    private List<Route> routes;

    @PostConstruct
    public void addRoutes() {
        // ignore icon
        ignorePaths("/favicon.ico");

        // add routes for static content
        addPublicResourceRoute();
        addWebjarsResourceRoute();

        // filter that inject some info
        ANY("/.*", routeContext -> {
            routeContext.setLocal("version", version);
            routeContext.next();
        });

        // add registered routes
        routeGroups.forEach(this::addRouteGroup);
        routes.forEach(this::addRoute);

        GET("/threadDump", new ThreadDumpHandler());
        GET("/sysInfo", new SystemInfoHandler());
    }

}
decebals commented 1 year ago

I also accidentally committed a bug fix in this PR.