1
This commit is contained in:
@@ -16,7 +16,7 @@ const upstreamBaseUrl = config.upstream_api_url || "http://127.0.0.1:8888";
|
||||
* @param {object} params.auth_ctx - 鉴权上下文(verifyRequest 返回的 context)
|
||||
* @returns {object} { status, data, headers }
|
||||
*/
|
||||
async function forwardRequest({ api_path, method, query, body, headers, auth_ctx }) {
|
||||
async function forwardRequest({ api_path, method, query, body, headers, auth_ctx = {} }) {
|
||||
const url = `${upstreamBaseUrl}${api_path}`;
|
||||
const start = Date.now();
|
||||
let status_code = 0;
|
||||
@@ -66,18 +66,23 @@ async function forwardRequest({ api_path, method, query, body, headers, auth_ctx
|
||||
* 写入 API 调用日志
|
||||
*/
|
||||
async function writeCallLog({ user_id, token_id, api_path, http_method, status_code, response_time }) {
|
||||
const now = new Date();
|
||||
const call_date = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
||||
await baseModel.biz_api_call_log.create({
|
||||
user_id,
|
||||
token_id,
|
||||
api_path,
|
||||
http_method,
|
||||
status_code,
|
||||
response_time,
|
||||
call_date,
|
||||
created_at: now,
|
||||
});
|
||||
try {
|
||||
const now = new Date();
|
||||
const call_date = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
||||
await baseModel.biz_api_call_log.create({
|
||||
user_id,
|
||||
token_id,
|
||||
api_path,
|
||||
http_method,
|
||||
status_code,
|
||||
response_time,
|
||||
call_date,
|
||||
created_at: now,
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
logs.error("[proxy] 写调用日志失败", e.message);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { forwardRequest };
|
||||
|
||||
Reference in New Issue
Block a user