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
23d82194
"...svn:/svn.code.sf.net/p/irrlicht/code/trunk@643" did not exist on "c00ce1d372a86762ca0fad9d3c6a342aa3feda89"
Commit
23d82194
authored
Oct 04, 2021
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http adapter injection
parent
d1c6a13a
Pipeline
#6071
passed with stages
in 48 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
6 deletions
+34
-6
README.md
README.md
+15
-4
package.json
package.json
+1
-1
src/koishi.interfaces.ts
src/koishi.interfaces.ts
+2
-0
src/koishi.service.ts
src/koishi.service.ts
+16
-1
No files found.
README.md
View file @
23d82194
...
...
@@ -23,13 +23,14 @@ import PluginOnebot from '@koishijs/plugin-onebot';
imports
:
[
KoishiModule
.
register
({
// Koishi config goes here
prefix
:
'
.
'
,
usePlugins
:
[
// Plugins to install
PluginDef
(
PluginOnebot
,
{
protocol
:
'
ws
'
,
endpoint
:
config
.
get
(
'
CQ_ENDPOINT
'
)
,
selfId
:
config
.
get
(
'
CQ_SELFID
'
)
,
token
:
config
.
get
(
'
CQ_TOKEN
'
)
,
endpoint
:
'
CQ_ENDPOINT
'
,
selfId
:
'
CQ_ENDPOINT
'
,
token
:
'
CQ_ENDPOINT
'
,
}),
],
})
...
...
@@ -44,14 +45,24 @@ You may also register Koishi plugins later.
```
ts
import
{
Module
}
from
'
@nestjs/common
'
;
import
{
HttpAdapterHost
}
from
'
@nestjs/core
'
;
import
{
ConfigModule
,
ConfigService
}
from
'
@nestjs/config
'
;
import
{
KoishiModule
,
PluginDef
}
from
'
koishi-nestjs
'
;
import
PluginOnebot
from
'
@koishijs/plugin-onebot
'
;
@
Module
({
imports
:
[
KoishiModule
.
registerAsync
({
useFactory
:
()
=>
({
imports
:
[
ConfigModule
.
forRoot
()],
inject
:
[
ConfigService
,
HttpAdapterHost
],
useFactory
:
async
(
config
:
ConfigService
,
adapterHost
:
HttpAdapterHost
,
)
=>
({
// Koishi config goes here
prefix
:
'
.
'
,
// OPTIONAL: Injects Http Server here to Koishi instance making routes functioning.
httpAdapter
:
adapterHost
.
httpAdapter
,
usePlugins
:
[
// Plugins to install
PluginDef
(
PluginOnebot
,
{
...
...
package.json
View file @
23d82194
{
"name"
:
"koishi-nestjs"
,
"version"
:
"1.0.
8
"
,
"version"
:
"1.0.
9
"
,
"description"
:
"Koishi.js as Nest.js Module"
,
"main"
:
"dist/index.js"
,
"typings"
:
"dist/index.d.ts"
,
...
...
src/koishi.interfaces.ts
View file @
23d82194
import
{
ModuleMetadata
,
Provider
,
Type
}
from
'
@nestjs/common
'
;
import
{
App
,
Plugin
,
MaybeArray
}
from
'
koishi
'
;
import
{
AbstractHttpAdapter
}
from
'
@nestjs/core
'
;
const
selectors
=
[
'
user
'
,
...
...
@@ -36,6 +37,7 @@ export function PluginDef<T extends Plugin>(
export
interface
KoishiModuleOptions
extends
App
.
Config
{
usePlugins
?:
KoishiModulePlugin
<
Plugin
>
[];
httpAdapter
:
AbstractHttpAdapter
;
}
export
interface
KoishiModuleOptionsFactory
{
...
...
src/koishi.service.ts
View file @
23d82194
...
...
@@ -7,6 +7,7 @@ import {
}
from
'
@nestjs/common
'
;
import
{
KOISHI_MODULE_OPTIONS
}
from
'
./koishi.constants
'
;
import
{
KoishiModuleOptions
}
from
'
./koishi.interfaces
'
;
import
{
Server
}
from
'
http
'
;
@
Injectable
()
export
class
KoishiService
...
...
@@ -14,12 +15,26 @@ export class KoishiService
implements
OnModuleInit
,
OnApplicationBootstrap
{
constructor
(
@
Inject
(
KOISHI_MODULE_OPTIONS
)
private
koishiModuleOptions
:
KoishiModuleOptions
,
private
readonly
koishiModuleOptions
:
KoishiModuleOptions
,
)
{
super
(
koishiModuleOptions
);
}
private
setHttpServer
()
{
if
(
this
.
koishiModuleOptions
.
httpAdapter
&&
!
this
.
koishiModuleOptions
.
port
)
{
const
httpServer
:
Server
=
this
.
koishiModuleOptions
.
httpAdapter
.
getHttpServer
();
if
(
httpServer
instanceof
Server
)
{
this
.
logger
(
'
app
'
).
info
(
'
App using Nest HTTP Server.
'
);
this
.
_httpServer
=
httpServer
;
}
}
}
onModuleInit
()
{
this
.
setHttpServer
();
if
(
this
.
koishiModuleOptions
.
usePlugins
)
{
for
(
const
pluginDesc
of
this
.
koishiModuleOptions
.
usePlugins
)
{
const
ctx
=
pluginDesc
.
select
...
...
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