Forráskód Böngészése

feat:后端项目,新增API网关模块,配置open-api接口的转发

yang yi 10 hónapja
szülő
commit
4323a7c749

+ 1 - 0
.gitignore

@@ -33,4 +33,5 @@
 !/open-api-commom
 !/open-api-client
 !/open-api-sdk
+!/open-api-gateway
 !.gitignore

+ 36 - 0
open-api-gateway/pom.xml

@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <groupId>org.springframework.boot</groupId>
+        <version>2.7.16</version>
+    </parent>
+
+    <artifactId>open-api-gateway</artifactId>
+    <groupId>space.anyi</groupId>
+    <version>1.0.0</version>
+    <description>
+        API网关
+    </description>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.cloud</groupId>
+            <artifactId>spring-cloud-starter-gateway</artifactId>
+            <version>3.1.9</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>

+ 19 - 0
open-api-gateway/src/main/java/space/anyi/openAPIGateway/Application.java

@@ -0,0 +1,19 @@
+package space.anyi.openAPIGateway;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ConfigurableApplicationContext;
+
+/**
+ * @ProjectName: yangyi-open-api-platform
+ * @FileName: Application
+ * @Author: 杨逸
+ * @Data:2025/11/20 10:35
+ * @Description:
+ */
+@SpringBootApplication
+public class Application {
+    public static void main(String[] args) {
+        ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args);
+    }
+}

+ 17 - 0
open-api-gateway/src/main/resources/application.yaml

@@ -0,0 +1,17 @@
+server:
+  port: 10001
+  servlet:
+    context-path: /open-api-gateway
+spring:
+  application:
+    name: open-api-gateway
+  cloud:
+    gateway:
+      routes:
+        - id: open-api-gateway
+          uri: http://localhost:10002
+          predicates:
+            - Path=/open-api-gateway/open-api/**
+          filters:
+            #分割路径,去掉前缀
+            - StripPrefix=1