Skip to content

Commit

Permalink
细节优化
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeRainStarSky committed May 24, 2024
1 parent 863fe37 commit 0e14e35
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ export default class Yunzai extends EventEmitter {
this.adapter = []

this.express = express()
this.express.quiet = []
for (const i of ["urlencoded", "json", "raw", "text"])
this.express.use(express[i]({ extended: false }))
this.express.use(req => {
req.next()
let quiet = false
for (const i of req.app.quiet)
if (req.originalUrl.startsWith(i)) {
quiet = true
break
}
req.rid = `${req.ip}:${req.socket.remotePort}`
req.sid = `${req.protocol}://${req.hostname}:${req.socket.localPort}${req.originalUrl}`
this.makeLog("mark", ["HTTP", req.method, "请求", req.headers, req.query, req.body], `${req.sid} <= ${req.rid}`)
req.next()
this.makeLog(quiet ? "debug" : "mark", ["HTTP", req.method, "请求", req.headers, req.query, req.body], `${req.sid} <= ${req.rid}`)
})
this.express.use("/exit", req => {
if (["::1", "::ffff:127.0.0.1"].includes(req.ip) || req.hostname == "localhost")
Expand Down

0 comments on commit 0e14e35

Please sign in to comment.