Skip to content

Three different exemple of how create your own reverse proxy inside your java web application.

License

Notifications You must be signed in to change notification settings

riccardobek/spring-reverse-proxy

Repository files navigation

Spring Reverse Proxy

This project is an implementation of a reverse proxy using either Spring Cloud Starter Netflix Zuul or Spring Cloud Starter Gateway (MVC or Webflux).

A reverse proxy is a type of server that acts as an intermediary between clients and servers, receiving requests from clients and forwarding them to the appropriate servers. The reverse proxy can be used for various purposes, such as load balancing, authentication and authorization, protection from cyber attacks, masking the server's IP address, and traffic compression. This increases security and improves scalability of online applications.

This repository contains three different Spring Boot projects for reverse proxy a Grafana Server:

  • spring-cloud-starter-netflix-zuul
  • spring-cloud-starter-gateway-mvc
  • spring-cloud-starter-gateway-webflux

Project 1: spring-cloud-starter-netflix-zuul

This project demonstrates how to use Zuul as a reverse proxy in a Spring Boot application. It includes a simple example of routing incoming requests to different microservices based on the URL path.

The library spring-cloud-starter-netflix-zuul has a limitation related to web sockets. I overcame it, creating a java websocket reverse proxy.

Project 2: spring-cloud-starter-gateway-mvc

This project showcases the use of Spring Cloud Gateway MVC for reverse proxying in a Spring Boot application. It includes examples of request routing, request filtering, and customizing the response for incoming requests.

In order to use the library spring-cloud-starter-gateway combined with MVC it is necessary to introduce in the properties file:

...
spring.main.web-application-type=reactive
...

This property allows you to overwrite the beans that have been declared with the same name.

Project 3: spring-cloud-starter-gateway-webflux

This project demonstrates the use of Spring Cloud Gateway WebFlux for reverse proxying in a Spring Boot application. It includes examples of request routing and filtering, and customization of the response for incoming requests using WebFlux.

Requirements

  • Java 11 or later
  • Docker installed on your system

Running the Project

To run the project, follow these steps:

  1. Clone the project repository to your local machine.
git clone https://github.com/riccardobek/spring-reverse-proxy.git 
  1. Navigate to the project directory.
cd spring-reverse-proxy
  1. Build the Docker images of the project.
docker-compose up
  1. Access the applications through the following endpoint:

License

This project is licensed under the MIT License. See LICENSE for more information.

Conclusion

This project provides a starting point for building a reverse proxy using either Zuul or Gateway in a Spring Boot application. You can customize it to meet your specific requirements.

About

Three different exemple of how create your own reverse proxy inside your java web application.

Topics

Resources

License

Stars

Watchers

Forks