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")
})