解决跨域问题

This commit is contained in:
tonglin 2022-12-22 11:25:47 +08:00
parent f1ab962be6
commit 47931c5969
3 changed files with 33 additions and 2 deletions

View File

@ -0,0 +1,21 @@
package com.gitlink.softbot.config;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@Component
public class AdminInterceptor extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
httpServletResponse.addHeader("Access-Control-Allow-Origin", "*");
httpServletResponse.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD,PATCH");
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
}

View File

@ -7,8 +7,8 @@ import com.gitlink.softbot.service.market.IMarketService;
import com.gitlink.softbot.vo.GetAllBotCategory;
import com.gitlink.softbot.vo.GetBotDetailResponse;
import com.gitlink.softbot.vo.MarketBotPagesVO;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@ -16,6 +16,7 @@ import javax.annotation.Resource;
@RestController
@CrossOrigin
public class MarketController {
@Resource
@ -103,4 +104,6 @@ public class MarketController {
Result<MarketBotPagesVO> result = new Result<>();
return result.build(marketBotPagesVO).build(200).build("success!");
}
}

View File

@ -4,12 +4,15 @@ import com.gitlink.softbot.global.exception.BotException;
import com.gitlink.softbot.global.vo.Result;
import com.gitlink.softbot.service.user.IUserService;
import com.gitlink.softbot.vo.*;
import org.springframework.web.bind.annotation.*;
import com.gitlink.softbot.vo.BotInputVO;
import javax.annotation.Resource;
import javax.validation.Valid;
@RestController
@CrossOrigin
public class UserController {
/**
@ -247,7 +250,10 @@ public class UserController {
public Result<?> getAllInstallBots(@RequestParam("user_id") Integer userId){
GetAllInstallBotsResponse getAllInstallBotsResponse = userService.getAllInstallBots(userId);
Result<GetAllInstallBotsResponse> result = new Result<>();
return result.build(getAllInstallBotsResponse).build(200).build("success!");
return result.
build(getAllInstallBotsResponse).
build(200).
build("success!");
}
@ -263,4 +269,5 @@ public class UserController {
return result.build(getStoreAllInstallBotResponse).build(200).build("success!");
}
}