{"id":18701026,"url":"https://github.com/toquery/example-spring-cloud-gateway","last_synced_at":"2026-04-16T08:38:10.110Z","repository":{"id":97927389,"uuid":"226756922","full_name":"ToQuery/example-spring-cloud-gateway","owner":"ToQuery","description":null,"archived":false,"fork":false,"pushed_at":"2025-12-28T11:44:39.000Z","size":280,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-30T22:19:54.621Z","etag":null,"topics":["demo","example","gateway","simple","spring","spring-boot","spring-cloud","spring-cloud-gateway"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ToQuery.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-12-09T01:06:28.000Z","updated_at":"2025-12-28T11:44:37.000Z","dependencies_parsed_at":"2023-12-26T05:28:48.315Z","dependency_job_id":"9bb58a50-4b25-49b8-80a6-ce22a59b01eb","html_url":"https://github.com/ToQuery/example-spring-cloud-gateway","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ToQuery/example-spring-cloud-gateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToQuery%2Fexample-spring-cloud-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToQuery%2Fexample-spring-cloud-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToQuery%2Fexample-spring-cloud-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToQuery%2Fexample-spring-cloud-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ToQuery","download_url":"https://codeload.github.com/ToQuery/example-spring-cloud-gateway/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ToQuery%2Fexample-spring-cloud-gateway/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31878502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T07:36:03.521Z","status":"ssl_error","status_checked_at":"2026-04-16T07:35:53.576Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["demo","example","gateway","simple","spring","spring-boot","spring-cloud","spring-cloud-gateway"],"created_at":"2024-11-07T11:40:14.965Z","updated_at":"2026-04-16T08:38:10.094Z","avatar_url":"https://github.com/ToQuery.png","language":"Java","readme":"# example-spring-cloud-gateway\n\n## 基础网关服务\n\n### 服务应用信息\n\n| 服务名   | 类型                   | 端口 | 说明     |\n| -------- | ---------------------- | ---- | -------- |\n| gateway  | oauth2-client          | 8080 |          |\n| resource | oauth2-resource-server | 9000 | 实际接口 |\n\n\n### 配置\n\n- 去除路径前缀\n\n```java\nclass RouteLocatorConfig {\n    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {\n        // 路径路由，去除前缀\n        // http://localhost/get/users/toquery -\u003e https://api.github.com/users/toquery\n        // http://localhost/rewrite/get -\u003e http://httpbin.org:80/get\n        builder.routes().route(\"path_rewrite_route\", r -\u003e r.path(\"/rewrite/**\")\n                .filters(f -\u003e f.rewritePath(\"/rewrite/(?\u003cpath\u003e.*)\", \"/${path}\"))\n                .uri(uri)\n        ).build();\n    }\n}\n```\n\n\n- 添加接口的权重和负载均衡\n\n```yaml\nspring:\n  application:\n    name: cloud-gateway\n  cloud:\n    gateway:\n      routes:\n      - id: service1_prod\n        uri: http://localhost:8081\n        predicates:\n        - Path=/test\n        - Weight=service1, 50\n      - id: service1_canary\n        uri: http://localhost:8082\n        predicates:\n        - Path=/test\n        - Weight=service1, 50\n```\n\n\n## 基于 Oauth2 的 SSO 认证授权网关\n\nSpring 官方原文：[https://spring.io/blog/2019/08/16/securing-services-with-spring-cloud-gateway](https://spring.io/blog/2019/08/16/securing-services-with-spring-cloud-gateway)\n\n![项目架构](docs/images/sso-gateway.png)\n\n### Oauth2 角色说明\n\n- server\n- client\n\n\n### 服务与端口\n\n| 服务名       | 类型                   | 端口 | 说明     |\n| ------------ | ---------------------- | ---- | -------- |\n| uaa          | oauth2-server          | 8090 |          |\n| sso-gateway  | oauth2-client          | 8080 |          |\n| sso-resource | oauth2-resource-server | 9000 | 资源服务 |\n\n\n### 快速使用\n\n```bash\n./build-images.sh\ndocker-compose up\n```\n\nIn an INCOGNITO or PRIVATE browser window...\n\n[http://localhost:8080/resource](http://localhost:8080/resource)\n\nYou'll be asked to login, use Username: `user1` and Password: `password`.\n\n\u003e These credentials are configured in the `[sso/uaa/uaa.yml](sso/uaa/uaa.yml)` file.\n\nYou'll be asked to Authorise that the resource-server is allowed to read your profile and check your scopes. \nClick \"Authorise` to allow this. You'll then be redirected to your original destination and the resource server \nwill print out your Subject's identity GUID.\n\n\u003e Resource was accessed by a584b8b8-eaf2-4280-b9c3-12f65cf8524b (sub)\n\n\n### Cleaning Up\n\nWhen you're done use `Ctrl-C` to stop the containers, `docker-compose down` to remove leftovers. `docker-compose rm -f`\n\n### Want to go again? \n\nProbably have to clear your cookies and restart the Docker bits... \n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoquery%2Fexample-spring-cloud-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoquery%2Fexample-spring-cloud-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoquery%2Fexample-spring-cloud-gateway/lists"}