我希望能够用完整的URL、头等记录每个AXIOS请求,但目前没有找到这样做的方法。
到目前为止,我所做的是基于此编写一个HTTP拦截器
answer
export class HttpLoggerInterceptor implements NestInterceptor {
intercept(
context: ExecutionContext,
call$: Observable<any>,
): Observable<any> {
return call$.pipe(
map(data => {
// pipe call to add / modify header(s) after remote method
const req = context.switchToHttp().getRequest();
return data;
}),
);
}
}
现在我浏览对象
req
和
context
在调试上的道具,但看不到ASIOS请求URL等,除非我错过了。
我的控制器路由(
api/data
在这种情况下)有n个HTTP外部调用发生,但拦截器只截取控制器调用,而不截取AXIOS调用。
有什么想法吗?
那就是
语境
对象:
args:Array(2) [IncomingMessage, ServerResponse]
constructorRef:class AppController { ⦠}
getRequest:() => â¦
getResponse:() => â¦
handler:data() { ⦠}
__proto__:Object {constructor: , getClass: , getHandler: , â¦}
那就是
情商
:
_dumped:false
_events:Object {}
_eventsCount:0
_maxListeners:undefined
_parsedOriginalUrl:Url {protocol: null, slashes: null, auth: null, â¦}
_parsedUrl:Url {protocol: null, slashes: null, auth: null, â¦}
_readableState:ReadableState {objectMode: false, highWaterMark: 16384, buffer: BufferList, â¦}
baseUrl:""
body:Object {}
client:Socket {connecting: false, _hadError: false, _handle: TCP, â¦}
complete:true
connection:Socket {connecting: false, _hadError: false, _handle: TCP, â¦}
destroyed:false
fresh:false
headers:Object {accept: "application/json, text/plain, */*", user-agent: "axios/0.18.0", host: "localhost:3000", â¦}
host:"localhost"
hostname:"localhost"
httpVersion:"1.1"
httpVersionMajor:1
httpVersionMinor:1
ip:"::ffff:127.0.0.1"
ips:Array(0)
method:"GET"
next:function next(err) { ⦠}
originalUrl:"/api/data"
params:Object {}
__proto__:Object {constructor: , __defineGetter__: , __defineSetter__: , â¦}
path:"/api/data"
protocol:"http"
query:Object {}
rawHeaders:Array(8) ["Accept", "application/json, text/plain, */*", "User-Agent", â¦]
rawTrailers:Array(0) []
readable:true
readableBuffer:BufferList
readableFlowing:null
readableHighWaterMark:16384
readableLength:0
res:ServerResponse {_events: Object, _eventsCount: 1, _maxListeners: undefined, â¦}
route:Route {path: "/api/data", stack: Array(1), methods: Object}
secure:false
socket:Socket {connecting: false, _hadError: false, _handle: TCP, â¦}
stale:true
statusCode:null
statusMessage:null
subdomains:Array(0)
trailers:Object {}
upgrade:false
url:"/api/data"
xhr:false