Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7188071
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
|
{
rawURL
:
string
},
mountable
:
Mountable
)
:
void
{
const
raw_url
=
typeof
url
===
"string"
?
url
:
url
.
rawURL
;
router
.
use
(
raw_url
,
Middlewares
.
extractContext
(),
Middlewares
.
parseBody
(),
handleHtmlPromise
);
mountable
.
init
();
// to automatically add trailing slashes:
router
.
get
(
raw_url
.
slice
(
0
,
-
1
),
async
(
ctx
,
next
)
=>
{
const
url2
=
ctx
.
URL
;
if
(
!
url2
.
pathname
.
endsWith
(
"/"
))
{
url2
.
pathname
+=
"/"
;
ctx
.
redirect
(
url2
.
pathname
);
}
await
next
();
});
router
.
use
(
raw_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
,
raw_url
);
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Tue, Jul 8, 07:52 (17 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
776090
Default Alt Text
mount.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment