# 默认路由规则
spring:
  cloud:
    gateway:
      default-filters:
        #- PrefixPath=/httpbin
        #- JwtParser=.*/login
        - AddResponseHeader=Cache-Control, no-cache
        - AddResponseHeader=Pragma, no-cache
        - AddResponseHeader=Expires, -1
        # - PeekRequestBody

      routes:
        # 数据范围为自身处理
        - id: wxapi_phone
          uri: ${wxapi.url}
          predicates:
            - Path=/api/my/**
            - Jwt=issuer, wxapp
          filters:
            - RewritePath=/api/my/(?<segment>.*), /api/$\{segment}
            - SetRequestParameter=scope, myself
            - SetRequestParameter=userId, {jwt:userId}
            - Forward
        # 小程序获取手机号
        - id: wxapi_phone
          uri: ${wxapi.url}
          predicates:
            - Path=/api/wxa/business/getuserphonenumber
          filters:
            - RewritePath=/api/(?<segment>.*), /api.weixin.qq.com/$\{segment}
        # 小程序接口
        - id: wxapi_demo
          uri: ${wxapi.url}
          predicates:
            - Path=/api/wxa/**
          filters:
            - RewritePath=/api/(?<segment>.*), /api.weixin.qq.com/$\{segment}
        # 静态文件获取接口
        - id: wxapi_static
          uri: ${uri.gaf}
          predicates:
            - Path=/api/profile/**
            - Method=Get
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # 字典查询
        - id: wxapi_dict_service
          uri: ${uri.gaf}
          predicates:
            - Path=/api/dict/**
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # 通知公告
        - id: wxapi_notice_service
          uri: ${uri.gaf}
          predicates:
            - Path=/api/notice/**
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # 微信小程序登录接口
        - id: wxapi_login
          uri: ${uri.gaf}
          predicates:
            - Path=/api/user/login
            - Method=Post
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # 微信用户注册
        - id: wxapi_user_register
          uri: ${uri.gaf}
          predicates:
            - Path=/api/user/register
            - Jwt=issuer, wxapp
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - SetRequestParameter=openId, {jwt:sub}
            - Forward
        # 微信小程序用户推荐码接口
        - id: wxapi_user_service
          uri: ${uri.gaf}
          predicates:
            - Path=/api/user/recommend/**.jpg
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # 微信小程序用户服务接口
        - id: wxapi_user_service
          uri: ${uri.gaf}
          predicates:
            - Path=/api/user/**
            - Jwt=issuer, wxapp
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - SetRequestParameter=userId, {jwt:userId}
            - Forward
        # 微信小程序模板页面接口
        - id: wxapi_template
          uri: ${uri.gaf}
          predicates:
            - Path=/api/template/**
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # 微信小程序菜单接口
        - id: wxapi_cms_menu
          uri: ${uri.gaf}
          predicates:
            - Path=/api/cms/wxAppMenu/**
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # 微信小程序CMS接口
        - id: wxapi_cms
          uri: ${uri.gaf}
          predicates:
            - Method=GET
            - Path=/api/cms/**
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # 微信小程序CMS发布信息接口
        - id: wxapi_cms_publish
          uri: ${uri.gaf}
          predicates:
            - Path=/api/cms/**
            - Jwt=issuer, wxapp
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - SetRequestParameter=userId, {jwt:userId}
            - Forward
        # 微信小程序获取系统配置接口
        - id: wxapi_sys_config
          uri: ${uri.gaf}
          predicates:
            - Path=/api/config/**
            - Method=GET
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # 微信小程序业务接口
        - id: wxapi_biz
          uri: ${uri.gaf}
          predicates:
            - Path=/api/**
            - Jwt=issuer, wxapp
          filters:
            - RewritePath=/api/(?<segment>.*), /$\{segment}
            - Forward
        # == 默认处理 ==
        - id: api_default
          uri: forward:///401 # default for unauthorized
          order: 1000
          predicates:
            - Path=/api/**
          filters:
            - SetStatus=401


