vue_music:build打包启动和webpack接口调用方式

1.webpack中接口调用方式

第一种webpack.dev.config.js

clipboard.png

2. 第二种

clipboard.png

2. build打包启动

1. 执行npm run build打包

使用了vue-router路由懒加载,所以app.js只有50KB

clipboard.png

2. 启动本地服务

在项目文件夹下,新建prod.server.js,然后node prod.server.js

var express = require('express')
var config = require('./config/index')
var axios = require('axios')
var app = express()
var port = process.env.PORT || config.build.port
var apiRoutes = express.Router()


apiRoutes.get('/getDiscList',function(req, res){
  console.log('1111111')
  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)
  })
})

apiRoutes.get('/lyric',function(req, res){
  console.log('222222')
  var url = 'https://szc.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) => {
    res.json(response)
  }).catch((e) => {
    console.log(e)
  })
})

apiRoutes.get('/getSongList',function(req, res){
  console.log('33333333')
  var url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg'

  axios.get(url, {
    headers: {
      referer: 'https://y.qq.com/',
      host: 'c.y.qq.com'
    },
    params: req.query
  }).then((response) => {
    res.json(response)
  }).catch((e) => {
    console.log(e)
  })
})

apiRoutes.get('/getHotKey',function(req, res){
  console.log('444444')
  var url = 'https://c.y.qq.com/splcloud/fcgi-bin/gethotkey.fcg'
  axios.get(url, {
    headers: {
      referer: 'https://y.qq.com/',
      host: 'c.y.qq.com'
    },
    params: req.query
  }).then((response) => {
    res.json(response.data)
  }).catch((e) => {
    console.log(e)
  })
})

apiRoutes.get('/search',function(req, res){
  console.log('55555')
  var url = 'https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp'

  axios.get(url, {
    headers: {
      referer: 'https://y.qq.com/',
      host: 'c.y.qq.com'
    },
    params: req.query
  }).then((response) => {
    res.json(response.data)
  }).catch((e) => {
    console.log(e)
  })
})

app.use('/api', apiRoutes)

app.use(express.static('./dist'))

module.exports = app.listen(port, function(err) {
  if(err) {
    console.log(err)
    return
  }
  console.log('listening at http://localhost:' + port + '\n')
})

注意:中间件的路径

clipboard.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值