1.6K Star 17.2K Fork 14K

若依 / RuoYi-Cloud

 / 详情

swagger: failed to fetch

已完成
创建于  
2020-06-16 12:08

输入图片说明

用localhost可以打开 用ip地址就出现这个问题~ 请问下如何解决这个问题

评论 (1)

刘岸江 创建了任务
刘岸江 关联仓库设置为若依/RuoYi-Cloud
展开全部操作日志

localhost不算跨域,如果带IP就是跨域了。你可以在网关添加配置
com.ruoyi.gateway.config.CrosConfig

package com.ruoyi.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.web.cors.reactive.CorsUtils;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

@Configuration
public class CrosConfig
{
    @Bean
    public WebFilter corsFilter()
    {
        return (ServerWebExchange ctx, WebFilterChain chain) -> {
            ServerHttpRequest request = ctx.getRequest();
            if (CorsUtils.isCorsRequest(request))
            {
                ServerHttpResponse response = ctx.getResponse();
                HttpHeaders headers = response.getHeaders();
                headers.add("Access-Control-Allow-Origin", "*");
                headers.add("Access-Control-Allow-Methods", "*");
                headers.add("Access-Control-Allow-Headers", "*");
                headers.add("Access-Control-Allow-Credentials", "true");
                if (request.getMethod() == HttpMethod.OPTIONS)
                {
                    response.setStatusCode(HttpStatus.OK);
                    return Mono.empty();
                }
            }
            return chain.filter(ctx);
        };
    }
}

若依 任务状态待办的 修改为已完成

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
1151004 y project 1578942802
Java
1
https://gitee.com/y_project/RuoYi-Cloud.git
git@gitee.com:y_project/RuoYi-Cloud.git
y_project
RuoYi-Cloud
RuoYi-Cloud

搜索帮助