Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3059784
logger.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
826 B
Referenced Files
None
Subscribers
None
logger.ts
View Options
import
{
Elysia
}
from
'elysia'
;
export
const
logger
=
({
methods
=
[
'GET'
,
'PUT'
,
'POST'
,
'DELETE'
]
}
=
{})
=>
new
Elysia
()
.
derive
({
as
:
'global'
},
()
=>
({
start
:
Date.now
()
}))
.
onBeforeHandle
({
as
:
'global'
},
ctx
=>
{
if
(
!
methods
.
includes
(
ctx
.
request
.
method
))
return
;
console
.
log
(
'<--'
,
ctx
.
request
.
method
,
ctx
.
path
);
})
.
onAfterHandle
({
as
:
'global'
},
ctx
=>
{
if
(
!
methods
.
includes
(
ctx
.
request
.
method
))
return
;
console
.
log
(
'-->'
,
ctx
.
request
.
method
,
ctx
.
path
,
ctx
.
set
.
status
??
Number
.
NaN
,
'in'
,
Date
.
now
()
-
ctx
.
start
,
'ms'
);
})
.
onError
({
as
:
'global'
},
ctx
=>
{
if
(
!
methods
.
includes
(
ctx
.
request
.
method
))
return
;
console
.
log
(
'-->'
,
ctx
.
request
.
method
,
ctx
.
path
,
ctx
.
set
.
status
,
'in'
,
ctx
.
start
?
Date
.
now
()
-
ctx.start
:
Number.NaN
,
'ms'
);
});
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Apr 3, 6:55 PM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
521750
Default Alt Text
logger.ts (826 B)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment