import { match } from "./C:/Users/Administrator/AppData/Local/Microsoft/TypeScript/2.6/node_modules/@types/minimatch";
import { response } from "./C:/Users/Administrator/AppData/Local/Microsoft/TypeScript/2.6/node_modules/@types/spdy
const express = require("express")
const config = require("./config/index")
const axios = require("axios")
const app = express();
const apiRoutes = express.Router() // server的路由分发代理
apiRoutes.get("/getDiscLisc", (req, res) => {
let url = "https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg"
axios.get(url, {
headers: { // 请求数据的时候 采取了两种: 一种是 jsonp npm封装 一种是node代理这种方式:请求后端发起请求数据服务器,设置headers的referer(请求来源地址)host:来源主机, 绕过同源策略,“欺骗数据服务器”
referer: "https://c.yy.qq.com/",
host: "c.y.qq.com"
},
params: req.query
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
apiRoutes.get("/lyric", (req, res) => {
const url = ‘https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg‘
axios.get(url, {
headers: {
referer: "https://c.yy,qq.com/",
host: "c.yy.com"
},
params: req.query
}).then((response) => {
let ret = response.data
if (typeof ret === ‘string‘) {
let reg = /^\w+\(({[^()]+})\)$/
let matches = ret.match(reg)
if (matches) {
}
}
})
// apiRoutes.get("/lyric", (req, res) => {
// })
})
app.use("/api", apiRoutes) // /api 作为代理地址,前端请求使用这个来请求后端数据 /api+你的前端路由
// 直接将静态资源(托管后的dist目录)作为 托管
app.use(express.static("./dist")) //这个就是之前说的 将 build 后的静态资源托管,优化,
// index/.html 里面的img icon 资源 可以放在 托管 static目录下
let port = process.env.PORT || config.build.port
module.exports = app.listen(port, (err) => {
if (err) {
console.log(err)
return
}
console.log("LIstening at http://localhost:" + port + "\n")
})