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 ...
随机推荐
- Java作业十三(2017-11-20)
/*使用一位数组解决 1 1 2 3 5 8 13 数列问题 斐波纳契数列 Fibonacci*/ package cn.GM; public class array { public static ...
- [转]Understanding OpenStack Authentication: Keystone PKI
The latest stable release of OpenStack, codenamed Grizzly, revolutionizes the way user authenticatio ...
- [IOT] 自制蓝牙工牌办公室定位系统 (一)—— 阿里物联网平台概览及打通端到云(硬核·干货)
目录:老少皆宜.超长干货文警告 1.快速入门创建产品 -- 小白,打包带走去吹牛 2.代码分析 -- 老炮,快速了解能用上 2.1 从start.sh分析开发环境如何自动构建 2.2 从sample. ...
- [Swift]LeetCode984. 不含 AAA 或 BBB 的字符串 | String Without AAA or BBB
Given two integers A and B, return any string S such that: S has length A + B and contains exactly A ...
- python之高阶函数和匿名函数
map() map()函数接收两个参数,一个是函数,一个是Iterable,map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回. def func(x): return ...
- Java操作符真的简单到易如反掌?
之前我写了一篇<吃人的那些Java名词:对象.引用.堆.栈和堆栈>,本以为凭借自己8年的Java编程经验足够把这些“吃人”的Java名词解释清楚了,但有网友不以为然,在文章底部评论说:“老 ...
- 【从零开始自制CPU之学习篇02】555定时器
555定时器是一种集成电路芯片,常被用于定时器.脉冲产生器和震荡电路.在CPU制作中作为pc(程序计数器)的主要组成部分.以下是我购买的NE555实拍图: NE555的针脚示意图: 555定时器各针脚 ...
- MSSQL TABLE COPY TABLE
SQL Server中,如果目标表存在: insert into 目标表 select * from 原表; SQL Server中,,如果目标表不存在: select * into 目标表 from ...
- asp.net core 系列 2 启动Startup类介绍
一.Startup类 ASP.NET Core 应用是一个控制台应用,它在其 Program.Main 方法中创建 Web 服务器.其中Main方法是应用的托管入口点,Main 方法调用 WebHos ...
- IDEA中MAVEN项目打JAR包的简单方法
Idea中为一般的非Web项目打Jar包是有自己的方法的,网上一搜就能查到很多. 但是如果是为Maven项目打Jar包,其实是很简单的,因为maven本身就有打Jar包的命令. 最简单的方法 ...