fix: log config

This commit is contained in:
lyz05
2024-01-10 23:30:49 +08:00
parent 8091d4b604
commit f038b78c49
4 changed files with 15 additions and 15 deletions

4
app.js
View File

@@ -23,7 +23,7 @@ app.set("trust proxy", true);
app.use(logger("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(express.urlencoded({ extended: false, validate: { trustProxy: false } }));
app.use(cookieParser());
// 加载静态资源
app.use(express.static(path.join(__dirname, "public")));
@@ -32,7 +32,7 @@ app.use("/assets", [
express.static(__dirname + "/node_modules/bootstrap/dist/"),
express.static(__dirname + "/node_modules/axios/dist/"),
]);
app.use("/upload", express.static(__dirname + "/upload"));
// app.use("/upload", express.static(__dirname + "/upload"));
// 加载路由
app.use("/", danmakuRouter);

View File

@@ -4,9 +4,9 @@ const leancloud = require("../utils/leancloud");
/* GET users listing. */
router.get("/", async function (req, res) {
leancloud.add("SubAccess", {
ip: req.ip,
ua: req.headers["user-agent"],
await leancloud.add("SubAccess", {
remoteIP: req.ip,
UA: req.headers["user-agent"],
user: req.query.user,
ctype: req.query.ctype
});

View File

@@ -63,7 +63,7 @@ async function build_response(url, req) {
console.log(e);
let err = JSON.stringify(e, Object.getOwnPropertyNames(e));
err = JSON.parse(err);
leancloud.add("DanmakuError", {
await leancloud.add("DanmakuError", {
ip: req.ip,
url,
err
@@ -108,7 +108,7 @@ async function index(req, res) {
/* GET home page. */
router.get("/", apiLimiter, async function (req, res) {
leancloud.add("DanmakuAccess", {
await leancloud.add("DanmakuAccess", {
remoteIP: req.ip,
url: req.query.url,
UA: req.headers["user-agent"]

View File

@@ -47,19 +47,19 @@ async function danmakuQuery(date, ip) {
return await query.count();
}
function add(className, obj) {
async function add(className, obj) {
if (!AV) return;
if (obj.ip || obj.remoteIP)
obj.ipCountry = getipCountry(obj.ip || obj.remoteIP);
if (obj.remoteIP)
obj.ipCountry = getipCountry(obj.remoteIP);
const classInstance = AV.Object.extend(className);
const record = new classInstance();
for (const key of Object.keys(obj)) {
record.set(key, obj[key]);
}
record.save().then((obj) => {
// 成功保存之后,执行其他逻辑
console.log(`${className}添加一条记录。objectId${obj.id}`);
});
console.log(record.attributes);
const o = await record.save()
// 成功保存之后,执行其他逻辑
console.log(`${className}添加一条记录。objectId${o.id}`);
}
function getipCountry(ip) {
@@ -67,7 +67,7 @@ function getipCountry(ip) {
const info = qqwry.searchIP(ip);
return info.Country + " " + info.Area;
} catch (e) {
return null;
return "";
}
}