Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010348
mount.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
mount.ts
View Options
import
Router
from
"@koa/router"
;
import
Koa
,
{
Context
}
from
"koa"
;
import
{
Middlewares
}
from
"sealious"
;
import
{
Mountable
}
from
"./page/mountable"
;
async
function
handleHtmlPromise
(
ctx
:
Context
,
next
:
Koa
.
Next
)
{
await
next
();
if
(
ctx
.
body
instanceof
Promise
)
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
ctx
.
body
=
await
ctx
.
body
;
}
ctx
.
set
(
"content-type"
,
"text/html;charset=utf-8"
);
}
export
function
mount
(
router
:
Router
,
url
:
string
,
mountable
:
Mountable
)
:
void
{
router
.
use
(
url
,
Middlewares
.
extractContext
(),
Middlewares
.
parseBody
(),
handleHtmlPromise
);
mountable
.
init
();
// to automatically add trailing slashes:
router
.
get
(
url
.
slice
(
0
,
-
1
),
async
(
ctx
,
next
)
=>
{
const
url2
=
ctx
.
URL
;
if
(
!
url2
.
pathname
.
endsWith
(
"/"
))
{
url2
.
pathname
+=
"/"
;
ctx
.
redirect
(
url2
.
toString
());
}
await
next
();
});
router
.
use
(
url
,
async
(
ctx
,
next
)
=>
{
ctx
.
set
(
"content-type"
,
"text/html;charset=utf-8"
);
const
access_result
=
await
mountable
.
canAccess
(
ctx
);
if
(
!
access_result
.
canAccess
)
{
ctx
.
status
=
403
;
ctx
.
body
=
access_result
.
message
||
"no access"
;
return
;
}
await
next
();
});
mountable
.
mount
(
router
,
url
);
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Wed, May 7, 19:41 (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
626095
Default Alt Text
mount.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment