Skip to content

Commit 038a895

Browse files
committed
docs: add koa get port api
1 parent 85a9254 commit 038a895

File tree

2 files changed

+56
-2
lines changed
  • site
    • docs/extensions
    • i18n/en/docusaurus-plugin-content-docs/current/extensions

2 files changed

+56
-2
lines changed

site/docs/extensions/koa.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ declare module '@midwayjs/koa/dist/interface' {
186186
abc: string;
187187
}
188188

189-
interface State{
189+
interface State {
190190
bbb: string;
191191
ccc: number;
192192
}
@@ -195,6 +195,33 @@ declare module '@midwayjs/koa/dist/interface' {
195195

196196

197197

198+
## 获取端口
199+
200+
通过 framework 或者 app 上的 `getPort()` 方法可以获取端口。
201+
202+
```typescript
203+
import { App, Configuration } from '@midwayjs/core';
204+
import * as koa from '@midwayjs/koa';
205+
206+
@Configuration({
207+
imports: [
208+
koa,
209+
// ...
210+
]
211+
// ...
212+
})
213+
export class MainConfiguration {
214+
@Inject()
215+
framework: koa.Framework;
216+
217+
async onServerReady(container, mainApp: koa.Application) {
218+
const port = this.framework.getPort();
219+
const port = this.mainApp.getPort();
220+
// ...
221+
}
222+
}
223+
```
224+
198225

199226

200227
## 配置

site/i18n/en/docusaurus-plugin-content-docs/current/extensions/koa.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ declare module '@midwayjs/koa/dist/interface' {
184184
abc: string;
185185
}
186186

187-
interface State{
187+
interface State {
188188
bbb: string;
189189
ccc: number;
190190
}
@@ -193,6 +193,33 @@ declare module '@midwayjs/koa/dist/interface' {
193193

194194

195195

196+
## Get Port
197+
198+
You can get the port through the `getPort()` method on the framework or app.
199+
200+
```typescript
201+
import { App, Configuration } from '@midwayjs/core';
202+
import * as koa from '@midwayjs/koa';
203+
204+
@Configuration({
205+
imports: [
206+
koa,
207+
// ...
208+
]
209+
// ...
210+
})
211+
export class MainConfiguration {
212+
@Inject()
213+
framework: koa.Framework;
214+
215+
async onServerReady(container, mainApp: koa.Application) {
216+
const port = this.framework.getPort();
217+
const port = this.mainApp.getPort();
218+
// ...
219+
}
220+
}
221+
```
222+
196223

197224

198225
## Configuration

0 commit comments

Comments
 (0)