Skip to content

Commit

Permalink
add request id
Browse files Browse the repository at this point in the history
  • Loading branch information
wuminzhe committed Apr 1, 2024
1 parent 29311a4 commit a568956
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 102 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dotenv": "^16.3.1",
"ethers": "^5.7.0",
"express": "^4.18.2",
"express-http-context": "^1.2.4"
"express-http-context": "^1.2.4",
"express-ruid": "^1.1.5"
}
}
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express, { Express, Request, Response } from "express";
var httpContext = require('express-http-context');
const ruid = require('express-ruid');
import { IEstimateFee } from "./interfaces/IEstimateFee";
import { ensureError } from "./errors";

Expand All @@ -11,8 +12,9 @@ console.log = (function() {

return function() {
const logSubTitle = httpContext.get('logTitle');
if (logSubTitle) {
var title = "[" + new Date().toUTCString() + "] - [" + logSubTitle + "]";
const rid = httpContext.get('rid');
if (logSubTitle && rid) {
var title = "[" + new Date().toUTCString() + "] [" + logSubTitle + "] [" + rid + "]";
} else {
var title = "[" + new Date().toUTCString() + "]";
}
Expand Down Expand Up @@ -40,6 +42,7 @@ app.use((_req, res, next) => {
})

app.use(httpContext.middleware);
app.use(ruid({ setInContext: true }));

app.get("/", (_req: Request, res: Response) => {
res.send("Hello, Darwinia");
Expand Down
Loading

0 comments on commit a568956

Please sign in to comment.