国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

vue 音樂App QQ音樂搜索列表最新接口跨域設(shè)置方法

2024-05-06 15:29:33
字體:
供稿:網(wǎng)友

 在 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 結(jié)合 node.js 代理后端請求 startconst express = require('express')const axios = require('axios')const app = express()var apiRoutes = express.Router()app.use('/api', apiRoutes)  //-------------------axios 結(jié)合 node.js 代理后端請求 endconst HOST = process.env.HOSTconst 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 結(jié)合 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 數(shù)據(jù)轉(zhuǎn)為 json 數(shù)據(jù)            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 結(jié)合 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)    }  })})            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 宁陕县| 武山县| 个旧市| 聂拉木县| 上饶市| 富平县| 新民市| 土默特左旗| 禄丰县| 苗栗县| 淅川县| 那坡县| 屏南县| 特克斯县| 临猗县| 庆安县| 依兰县| 东辽县| 敦化市| 工布江达县| 丹棱县| 两当县| 鹤庆县| 晋中市| 新野县| 黑水县| 垦利县| 洱源县| 安阳县| 嘉峪关市| 丹阳市| 虞城县| 厦门市| 苏尼特左旗| 闸北区| 马边| 广元市| 澎湖县| 惠水县| 化隆| 安国市|