This is a simple Spring Boot Gateway implementation. This gateway was created to be used with our final project in the Web Service course at IT-Högskolan, Gothenburg.
This service connects our schoolmates microservices and provides a secure entrance to our service cluster.
The Gateway is by default configured to run with the Authentication service, the Image service and the URL shortener service.
To add more routes/services, please see step 7 of Deployment
- Create network:
docker network create net - Start consul:
docker run -d -p 8500:8500 -p 8600:8600/udp --name=consul --network=net consul agent -server -ui -node=server-1 -bootstrap-expect=1 -client='0.0.0.0' - Add config file to consul
- Open Consul UI: http://localhost:8500
- Go to Key/Value
- Create the following folder structure:
config/gateway/ - Create a file named:
data(yaml format) - Add the following YML data:
server:
port: 8000
spring:
cloud:
consul:
discovery:
register: false
registerHealthCheck: false
host: consul
gateway:
routes:
- id: authentication
uri: lb://authentication
predicates:
- Path=/auth/**
filters:
- RewritePath=/auth/(?<path>.*), /$\{path}
- id: image-service
uri: lb://image-service
predicates:
- Path=/images/**
filters:
- RewritePath=/images/(?<path>.*), /images/$\{path}
- id: url-shortening-service
uri: lb://url-shortener
predicates:
- Path=/short/**, /s/**
filters:
- RewritePath=/short/(?<path>.*), /short/$\{path}
- RewritePath=/s/(?<path>.*), /s/$\{path}
path:
matchers:
permit: /s/**
authenticate: /images/**,/short/**
key:
public: <your-public-key- Add your Public JWT key to the config
- Get a Private/Public keypair from our classmates Authentication service
- Make sure the Private key in the
Authentication Consul configis paired with the Public Key theGateway Consul config - Add your Public key where
<your-public-key>is written, make sure to remove any""surrounding it.
- Clone this project
git clone https://github.com/Patlenlix/gateway.git - Open project locally and run
mvn package - Start Docker desktop
- Run Dockerfile while standing in project root
docker build -t gateway:latest . - Start the Gateway container
docker run -d --name gateway -p 8000:8000 --network=net -e CONSUL_HOST=consul gateway:latest - To add more routes/services
- Add a new route in
Consul Key/Value config filewith appropriatepredicates(paths) andfilters(redirections) - Add a new
endpointunderpath.matchers.authenticatematching the paths of the new service, separate with ","
- Add a new route in