paulwoods / gateway-and-clients

example showing a spring boot gateway, and 2 react clients

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gateway-and-clients

example showing a spring boot gateway, and 2 react clients

We want to access each client though these URLS:

When we run the application (on localhost), we use these ports:

  • gateway: 8080
  • client1: 5173
  • client2: 5174

Spring Boot Gateway

The gateway is a spring boot app, with this dependency:

implementation 'org.springframework.cloud:spring-cloud-starter-gateway'

The configuration file will list each client. The clients are run on different ports, and have a path to uniquely define the URL to each.

server:
  port: 8080

spring:
  cloud:
    gateway:
      routes:
        - id: client1
          uri: http://localhost:5173
          predicates:
            - Path=/client1/**
          filters:
            - StripPrefix=0
        - id: client2
          uri: http://localhost:5174
          predicates:
            - Path=/client2/**
          filters:
            - StripPrefix=0

React Clients

The React clients are Vite projects, with react and typescript. Update vite.config.ts, and add the base:

export default defineConfig({
    plugins: [react()],
    base: "/client1"
})

About

example showing a spring boot gateway, and 2 react clients

License:Apache License 2.0


Languages

Language:TypeScript 38.4%Language:JavaScript 25.3%Language:HTML 20.7%Language:Java 15.5%