vue_music:build打包启动和webpack接口调用方式
1.webpack中接口调用方式
第一种webpack.dev.config.js
2. 第二种
2. build打包启动
1. 执行npm run build打包
使用了vue-router路由懒加载,所以app.js只有50KB
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') })
注意:中间件的路径
相关推荐
不知道该写啥QAQ 2020-11-12
webfullStack 2020-11-09
Yvettre 2020-09-15
想做大牛的蜗牛 2020-10-30
gloria0 2020-10-26
gaojie0 2020-09-11
SelinaChan 2020-08-14
不知道该写啥QAQ 2020-08-09
gloria0 2020-08-09
不知道该写啥QAQ 2020-08-02
hline 2020-07-29
SelinaChan 2020-07-28
wangdianyong 2020-07-23
webpackvuees 2020-07-23
yqoxygen 2020-07-20
不知道该写啥QAQ 2020-07-18
waterv 2020-07-18
81463166 2020-07-17