以前,spring boot的后端已部署在服务器上,并且服务器的后端已与本地VUE项目链接,并且可以登录。 但是,使用公共IP访问云上的项目将报告错误405,如下图所示。
打开浏览器的【检查网络】,找到请求,如下所示,xxx表示公网IP
http://xxx.xxx.xxx.xxx/login/auth?username=admin&password=123456
它无法返回结果。
但是,如果将请求更改为端口8080,如下所示,则可以正常返回结果 http://xxx.xxx.xxx.xxx:8080/login/auth?username=admin&password=123456
但是,您可以使用本地[npm run dev]直接访问启动的项目。下图显示了云上本地VUE + spring引导的登录状态。您可以登入
问题在于,对端口8080的请求将具有正确的返回值,但是VUE项目已部署在服务器上并在HTTP的端口80上运行。可以使用哪种修改来通过8080发送请求?
config / index.js如下:
var path = require('path')
module.exports = {
build: {
env: require('./prod.env'),
index: path.resolve(__dirname, '../dist/index.html'),
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',
productionSourceMap: true,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin productionGzip: false,
productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report
},
dev: {
env: require('./dev.env'),
host: 'localhost',
//host: 'PUBLIC IP',
//port: 9520 port: 8080,
autoOpenBrowser: true,
autoOpenPage: '/login',
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
// target: 'http://localhost:8080',
target: 'http://PUBLIC IP:8080',
pathRewrite: {
'^/api': '/'
}
}
},
}
}