前后端跨域/ 同时运行两个项目

(1)后端配置端口

复制代码
server:
  port: 90

(2)前端 配置跨域资源共享(CORS)

复制代码
devServer: {
  disableHostCheck: true,
  port: 8088,
  proxy: {
    '/openapi': {
      target: 'http://192.168.31.109:90',
      ws: false,
      changeOrigin: true
    },

其它信息

默认端口80通常用于HTTP协议,是Web服务器默认监听的端口

所以在后端端口配置为80的时候,前端可以不写,就像下面这样

复制代码
devServer: {
  disableHostCheck: true,
  port: 8088,
  proxy: {
    '/openapi': {
      target: 'http://192.168.31.109',
      ws: false,
      changeOrigin: true
    },

所以同时运行两个项目的话,需要 更改后端的端口,和前端对应的端口配置

相关推荐
古译汉书15 小时前
【IoT死磕系列】Day 3:学习HTTP!实战:STM32手写GET请求获取天气实战(附源码+八股文)
数据结构·stm32·物联网·网络协议·学习·算法·http
南部余额16 小时前
Spring Boot ResponseEntity响应处理与文件下载实战
spring boot·后端·http
Starry_hello world1 天前
Linux http代码
linux·运维·http
九狼2 天前
Flutter SSE 流式响用 Dio 实现 OpenAI 兼容接口的逐 Token 输出
http·设计模式·api
nix.gnehc2 天前
在K8s集群中部署Traefik并验证Python HTTP服务
python·http·kubernetes
执行部之龙2 天前
HTTP常见面试题总结
网络·网络协议·http
猫头虎2 天前
web开发常见问题解决方案大全:502/503 Bad Gateway/Connection reset/504 timed out/400 Bad Request/401 Unauthorized
运维·前端·nginx·http·https·gateway·openresty
无籽西瓜a3 天前
SSL/TLS工作流程以及HTTP与HTTPS详解
http·https·ssl
之歆5 天前
Varnish HTTP 缓存服务器完全指南
服务器·http·缓存