vue 音乐App QQ音乐搜索列表最新接口跨域设置
在 webpack.dev.config.js中
'use strict'
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const path = require('path')
const baseWebpackConfig = require('./webpack.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const portfinder = require('portfinder')
//-------------------axios 结合 node.js 代理后端请求 start
const express = require('express')
const axios = require('axios')
const app = express()
var apiRoutes = express.Router()
app.use('/api', apiRoutes)
//-------------------axios 结合 node.js 代理后端请求 end const HOST = process.env.HOST
const PORT = process.env.PORT && Number(process.env.PORT) const devWebpackConfig = merge(baseWebpackConfig, {
module: {
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap, usePostCSS: true })
},
// cheap-module-eval-source-map is faster for development
devtool: config.dev.devtool, // these devServer options should be customized in /config/index.js
devServer: {
clientLogLevel: 'warning',
historyApiFallback: {
rewrites: [
{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') },
],
},
//----------------axios 结合 node.js 代理后端请求
before(app) {
// 推荐热门歌单
app.get('/api/getDiscList', function(req, res) {
var url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'
axios.get(url, {
headers: {
referer: 'https://c.y.qq.com/',
host: 'c.y.qq.com'
},
params: req.query
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
}),
// 歌词
app.get('/api/getLyric', function(req, res) {
var url = 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg' axios.get(url, {
headers: {
referer: 'https://c.y.qq.com/',
host: 'c.y.qq.com'
},
params: req.query
})
.then((response) => {
// jsonp 数据转为 json 数据
var result = response.data
if (typeof result === 'string') {
var reg = /^\w+\(({[^()]+})\)$/
var matches = result.match(reg) if (matches) {
result = JSON.parse(matches[1])
}
}
res.json(result)
// res.json(response.data)
})
.catch((error) => {
console.log(error)
})
}),
//搜索列表接口
// https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp
app.get('/api/search', function(req, res) {
var url = 'https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp'
axios.get(url, {
headers: {
referer: 'https://c.y.qq.com/',
host: 'c.y.qq.com'
},
params: req.query
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
},
//----------------axios 结合 node.js 代理后端请求
hot: true,
contentBase: false, // since we use CopyWebpackPlugin.
compress: true,
host: HOST || config.dev.host,
port: PORT || config.dev.port,
open: config.dev.autoOpenBrowser,
overlay: config.dev.errorOverlay ? { warnings: false, errors: true } : false,
publicPath: config.dev.assetsPublicPath,
proxy: config.dev.proxyTable,
quiet: true, // necessary for FriendlyErrorsPlugin
watchOptions: {
poll: config.dev.poll,
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': require('../config/dev.env')
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(), // HMR shows correct file names in console on update.
new webpack.NoEmitOnErrorsPlugin(),
// https://github.com/ampedandwired/html-webpack-plugin
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
inject: true
}),
// copy custom static assets
new CopyWebpackPlugin([{
from: path.resolve(__dirname, '../static'),
to: config.dev.assetsSubDirectory,
ignore: ['.*']
}])
]
}) module.exports = new Promise((resolve, reject) => {
portfinder.basePort = process.env.PORT || config.dev.port
portfinder.getPort((err, port) => {
if (err) {
reject(err)
} else {
// publish the new Port, necessary for e2e tests
process.env.PORT = port
// add port to devServer config
devWebpackConfig.devServer.port = port // Add FriendlyErrorsPlugin
devWebpackConfig.plugins.push(new FriendlyErrorsPlugin({
compilationSuccessInfo: {
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`],
},
onErrors: config.dev.notifyOnErrors ? utils.createNotifierCallback() : undefined
})) resolve(devWebpackConfig)
}
})
})
在请求金封装的接口中
/*
*搜索列表
*/
export function getSearch(query,page,zhida,perpage) {
const url = '/api/search' //在webpack.dev.config启用了代理跨域
// const url ='https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp'
console.log(url)
const data = Object.assign({}, commonParams, {
// g_tk:5381,
// uin:0,
// format:json,
// inCharset:utf-8,
// outCharset:utf-8,
// notice:0,
// platform:h5,
// needNewCode:1,
// w:query,
// zhidaqu:1,
// catZhida: zhida ? 1 : 0,
// t:0,
// flag:1,
// ie:utf-8,
// sem:1,
// aggr:0,
// perpage:20,
// n:20,
// p:page,
// n: perpage,
// remoteplace:txt.mqq.all,
// _:1537612841753
//-----------------------------
// w: query,
// p: page,
// perpage,
// n: perpage,
// catZhida: zhida ? 1 : 0,
// zhidaqu: 1,
// t: 0,
// flag: 1,
// ie: 'utf-8',
// sem: 1,
// aggr: 0,
// remoteplace: 'txt.mqq.all',
// uin: 0,
// needNewCode: 1,
// platform: 'h5',
// g_tk:5381,
// _:1537612841753
//---------------------------------测试官方数据
g_tk:5381,
uin:0,
format:'json',
inCharset:'utf-8',
outCharset:'utf-8',
notice:0,
platform:'h5',
needNewCode:1,
w:query,
zhidaqu:1,
catZhida: zhida ? 1 : 0,
t:0,
flag:1,
ie:'utf-8',
sem:1,
aggr:0,
perpage:perpage,
n:20,
p:page,
remoteplace:'txt.mqq.all',
_:1537612841753
}) return axios.get(url, {
params: data
}).then((res) => {
//成功后返回
return Promise.resolve(res.data)
})
}
vue 音乐App QQ音乐搜索列表最新接口跨域设置的更多相关文章
- Mac下的Chrome或Safari访问跨域设置,MBP上使用模拟器Simulator.app或iphone+Safari调试网页
Mac下的Chrome或Safari访问跨域设置: mac下终端启动Chrome $ open -a Google\ Chrome --args --disable-web-security 或 /A ...
- vue proxyTable 接口跨域请求调试
在不同域之间访问是比较常见,在本地调试访问远程服务器....这就是有域问题. VUE解决通过proxyTable: 在 config/index.js 配置文件中 dev: { env: requir ...
- vue proxyTable 接口跨域请求调试(五)
在不同域之间访问是比较常见,在本地调试访问远程服务器....这就是有域问题. VUE解决通过proxyTable: 在 config/index.js 配置文件中 dev: { env: requir ...
- 跨域解决方案之JSONP,通过借助调用百度搜索的API了解跨域案例
跨域解决方案之JSONP 同源策略 同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web ...
- Vue的跨域设置
1.在使用vue开发的时候经常要涉及到跨域的问题,其实在vue cli中是有我们设置跨域请求的文件的. 2.当跨域无法请求的时候我们可以修改工程下config文件夹下的index.js中的dev:{} ...
- Vue请求第三方接口跨域最终解决办法!2020最终版!
废话少说,再百度的近三个小时尝试了近10种方法无解后,终于皇天不负有心人! 这个vue axios 跨域问题被我解决了! 需求:请求客户端ip地址获取客户ip,再根据ip获取用户位置 工具:Vue,a ...
- vue 新版本 webpack 代理 跨域设置
旧版本中:dev-server.js 这段去掉 var apiRoutes = express.Router() //getList apiRoutes.get('/getDiscList', fun ...
- vue axios 请求本地接口端口不一致出现跨域设置代理
首先在config下面的index.js,设置跨域代理 在axios请求的时候 用'/api/' 替代baseURL 最重要的就是设置完必须重新 npm run dev 否则不生效
- vue+java后台通信报403,cors解决跨域问题(该贴说的不是很清楚,不过大概如此,可再去网上查相关内容)
前端是vue2.0,网络请求用的是axios,后端是springboot2.0 用axios向后端发送post请求,结果得到一个403无权限的错误,莫名其妙啊,我明明发送的是post请,但在chrom ...
随机推荐
- tensorflow-线性函数训练例子一
import tensorflow as tfimport numpy as np #create datax_data = np.random.rand(100).astype(np.float32 ...
- Batch入门教程丨第二章:认识变量相关概念
在前两期的学习内容中,我们已经了解了Batch入门教程有关的知识和编程方法,如何编写和运行Windows Batch程序,脚本语言的入门方式等,今天我们将继续深入学习Batch入门教程之认识变量相关概 ...
- [Swift]LeetCode786. 第 K 个最小的素数分数 | K-th Smallest Prime Fraction
A sorted list A contains 1, plus some number of primes. Then, for every p < q in the list, we co ...
- postgresql 基础sql
创建用户和密码:crate user 用户名 with password '密码' : 创建 alter user 用户名 with password ’密码' ; 修改用户密码 查看用户信息: se ...
- 关于Python pandas模块输出每行中间省略号问题
关于Python数据分析中pandas模块在输出的时候,每行的中间会有省略号出现,和行与行中间的省略号....问题,其他的站点(百度)中的大部分都是瞎写,根本就是复制黏贴以前的版本,你要想知道其他问题 ...
- Mysql的两种偏移量分页写法
当一个查询语句偏移量offset很大的时候,如select * from table limit 10000,10 , 先获取到offset的id后,再直接使用limit size来获取数据,效率会有 ...
- 3-4 计算属性的setter和getter
Vue中的计算属性的setter和getter //如上,fullName这个方法在取这个数据的时候,会执行get中的方法:而在设置数据时,会执行set中的方法.其中set中有个参数(value),用 ...
- Python——day11 函数(对象、名称空间、作用域、嵌套、闭包)
一.函数对象 函数名就是存放了函数的内存地址,存放了内存地址的变量都是对象,即 函数名 就是 函数对象 函数对象的应用 1. 可以直接被引用 fn = cp_fn 2 .可以当作函数参数传递 c ...
- selenium下拉到页面最底端
selenium操控浏览器下拉到页面最底端: #!/usr/bin/env python # -*- coding: utf-8 -*- from selenium import webdriver ...
- Hystrix针对不可用服务的保护机制以及引入缓存
之前我写过一篇博文,通过案例了解Hystrix的各种基本使用方式,在这篇文章里,我们是通过Hystrix调用正常工作的服务,也就是说,Hytrix的保护机制并没有起作用,这里我们将在HystrixPr ...