Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
Koishi Nestjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
3rdeye
Koishi Nestjs
Commits
3b23fc5d
Commit
3b23fc5d
authored
Jan 30, 2023
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rework with http server
parent
7eecf9c8
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
108 additions
and
179 deletions
+108
-179
package-lock.json
package-lock.json
+105
-113
package.json
package.json
+1
-1
src/koishi.service.ts
src/koishi.service.ts
+2
-17
src/utility/koa-router.ts
src/utility/koa-router.ts
+0
-31
tests/koishi-tests.spec.ts
tests/koishi-tests.spec.ts
+0
-9
tests/utility/testing-module.ts
tests/utility/testing-module.ts
+0
-8
No files found.
package-lock.json
View file @
3b23fc5d
This diff is collapsed.
Click to expand it.
package.json
View file @
3b23fc5d
...
...
@@ -33,7 +33,7 @@
"peerDependencies"
:
{
"@nestjs/common"
:
"^9.0.3 || ^8.0.0"
,
"@nestjs/core"
:
"^9.0.3 || ^8.0.0"
,
"koishi"
:
"^4.11.
1
"
,
"koishi"
:
"^4.11.
4
"
,
"rxjs"
:
"^7.5.5"
},
"devDependencies"
:
{
...
...
src/koishi.service.ts
View file @
3b23fc5d
import
{
Command
,
Context
}
from
'
koishi
'
;
import
{
Command
,
Context
,
Router
}
from
'
koishi
'
;
import
{
Inject
,
Injectable
,
...
...
@@ -10,15 +10,13 @@ import {
KoishiCommandInterceptorRegistration
,
KoishiModuleOptions
,
}
from
'
./utility/koishi.interfaces
'
;
import
{
createServer
,
Server
}
from
'
http
'
;
import
{
Server
}
from
'
http
'
;
import
Koa
from
'
koa
'
;
import
KoaBodyParser
from
'
koa-bodyparser
'
;
import
{
KoishiMetascanService
}
from
'
./providers/koishi-metascan.service
'
;
import
{
KOISHI_MODULE_OPTIONS
,
KoishiIpSym
}
from
'
./utility/koishi.constants
'
;
import
{
KoishiLoggerService
}
from
'
./providers/koishi-logger.service
'
;
import
{
KoishiHttpDiscoveryService
}
from
'
./koishi-http-discovery/koishi-http-discovery.service
'
;
import
WebSocket
from
'
ws
'
;
import
{
KoishiNestRouter
}
from
'
./utility/koa-router
'
;
import
'
./utility/koishi.workarounds
'
;
import
'
./utility/koishi.declares
'
;
import
{
selectContext
}
from
'
koishi-thirdeye
'
;
...
...
@@ -43,7 +41,6 @@ export class KoishiService
});
this
.
baseDir
??
=
process
.
cwd
();
this
.
interceptors
=
this
.
koishiModuleOptions
.
globalInterceptors
;
this
.
router
=
new
KoishiNestRouter
();
this
.
_nestKoaTmpInstance
.
use
((
ctx
,
next
)
=>
{
ctx
.
request
.
ip
=
ctx
.
req
[
KoishiIpSym
];
return
next
();
...
...
@@ -63,18 +60,6 @@ export class KoishiService
this
.
router
.
_http
=
httpServer
;
}
else
{
this
.
logger
(
'
app
'
).
info
(
'
No http adapters found from Nest application.
'
);
const
tmpServer
=
createServer
(
this
.
_nestKoaTmpInstance
.
callback
());
this
.
router
.
_http
=
tmpServer
;
this
.
router
.
_ws
=
new
WebSocket
.
Server
({
server
:
tmpServer
,
});
this
.
router
.
_ws
.
on
(
'
connection
'
,
(
socket
,
request
)
=>
{
for
(
const
manager
of
this
.
router
.
wsStack
)
{
if
(
manager
.
accept
(
socket
,
request
))
return
;
}
socket
.
close
();
});
}
}
...
...
src/utility/koa-router.ts
deleted
100644 → 0
View file @
7eecf9c8
import
KoaRouter
from
'
@koa/router
'
;
import
{
Context
,
MaybeArray
,
remove
,
WebSocketLayer
}
from
'
koishi
'
;
import
{
IncomingMessage
}
from
'
http
'
;
import
WebSocket
from
'
ws
'
;
export
class
KoishiNestRouter
extends
KoaRouter
{
wsStack
:
WebSocketLayer
[]
=
[];
/**
* hack into router methods to make sure that koa middlewares are disposable
*/
override
register
(...
args
:
Parameters
<
KoaRouter
[
'
register
'
]
>
)
{
const
layer
=
super
.
register
(...
args
);
const
context
:
Context
=
this
[
Context
.
current
];
context
?.
state
.
disposables
.
push
(()
=>
{
remove
(
this
.
stack
,
layer
);
});
return
layer
;
}
ws
(
path
:
MaybeArray
<
string
|
RegExp
>
,
callback
?:
(
socket
:
WebSocket
,
request
:
IncomingMessage
)
=>
void
,
)
{
const
layer
=
new
WebSocketLayer
(
this
,
path
,
callback
);
this
.
wsStack
.
push
(
layer
);
const
context
:
Context
=
this
[
Context
.
current
];
context
?.
state
.
disposables
.
push
(()
=>
layer
.
close
());
return
layer
;
}
}
tests/koishi-tests.spec.ts
View file @
3b23fc5d
...
...
@@ -186,13 +186,4 @@ describe('Koishi in Nest.js', () => {
expect
(
command
).
toBeDefined
();
expect
(
command
.
execute
({
options
:
{}
})).
resolves
.
toBe
(
'
miiii
'
);
});
it
(
'
should handle partial dep
'
,
async
()
=>
{
koishiApp
[
'
ping
'
]
=
{
ping
:
'
pong
'
};
expect
(
await
koishiApp
.
waterfall
(
<
EventName
>
'
ping
'
)).
toBe
(
'
pong
'
);
koishiApp
[
'
ping
'
]
=
undefined
;
expect
(
await
koishiApp
.
waterfall
(
<
EventName
>
'
ping
'
)).
toBeUndefined
();
koishiApp
[
'
ping
'
]
=
{
ping
:
'
pong
'
};
expect
(
await
koishiApp
.
waterfall
(
<
EventName
>
'
ping
'
)).
toBe
(
'
pong
'
);
});
});
tests/utility/testing-module.ts
View file @
3b23fc5d
...
...
@@ -96,14 +96,6 @@ export class KoishiTestService {
async
onAbstract
(@
PutValue
(
'
{{abstract.content}}
'
)
content
:
string
)
{
return
content
;
}
@
UsingService
(
'
ping
'
)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
@
UseEvent
(
'
ping
'
)
async
onPing
()
{
return
'
pong
'
;
}
}
@
RegisterSchema
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment