Skip to content

Commit ea225aa

Browse files
committed
refactor: remove server.close method and export middleware NextFn
1 parent 343c9cb commit ea225aa

File tree

5 files changed

+4
-54
lines changed

5 files changed

+4
-54
lines changed

src/server/main.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -227,27 +227,6 @@ export class Server<NamedMiddleware extends Record<string, LazyImport<Middleware
227227
this.#underlyingHttpServer = server
228228
}
229229

230-
/**
231-
* Close the underlying HTTP server
232-
*/
233-
close() {
234-
return new Promise<void>((resolve, reject) => {
235-
if (!this.#underlyingHttpServer || !this.#underlyingHttpServer.listening) {
236-
resolve()
237-
return
238-
}
239-
240-
this.#underlyingHttpServer.close((error) => {
241-
/* c8 ignore next 3 */
242-
if (error) {
243-
return reject(error)
244-
}
245-
246-
resolve()
247-
})
248-
})
249-
}
250-
251230
/**
252231
* Returns reference to the underlying HTTP server
253232
* in use

src/types/base.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* file that was distributed with this source code.
88
*/
99

10+
export type { NextFn } from '@poppinss/middleware/types'
11+
1012
/**
1113
* Class constructor type
1214
*/

src/types/middleware.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
*/
99

1010
import type { ContainerResolver } from '@adonisjs/fold'
11-
import type { NextFn } from '@poppinss/middleware/types'
1211

13-
import type { Constructor } from './base.js'
12+
import type { Constructor, NextFn } from './base.js'
1413
import type { HttpContext } from '../http_context/main.js'
1514

1615
/**

src/types/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* file that was distributed with this source code.
88
*/
99

10+
import type { QSParserConfig } from './qs.js'
1011
import type { Constructor } from './base.js'
1112
import type { RequestConfig } from './request.js'
1213
import type { ResponseConfig } from './response.js'
1314
import type { HttpContext } from '../http_context/main.js'
14-
import { QSParserConfig } from './qs.js'
1515

1616
/**
1717
* Error handler to handle HTTP errors

tests/server.spec.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,6 @@ test.group('Server', () => {
4747

4848
assert.strictEqual(server.getNodeServer(), httpServer)
4949
})
50-
51-
test('close node server ', async ({ assert }) => {
52-
assert.plan(1)
53-
54-
const app = new AppFactory().create()
55-
const server = new ServerFactory().merge({ app }).create()
56-
server.use([], [], {})
57-
58-
const httpServer = createServer(() => {}).listen(3000)
59-
server.setNodeServer(httpServer)
60-
61-
httpServer.on('close', () => {
62-
assert.isFalse(httpServer.listening)
63-
})
64-
65-
await server.close()
66-
})
67-
68-
test('noop when http server is not listening or not set', async ({ assert }) => {
69-
const app = new AppFactory().create()
70-
const server = new ServerFactory().merge({ app }).create()
71-
server.use([], [], {})
72-
73-
assert.doesNotRejects(() => server.close())
74-
75-
const httpServer = createServer(() => {})
76-
server.setNodeServer(httpServer)
77-
78-
assert.doesNotRejects(() => server.close())
79-
})
8050
})
8151

8252
test.group('Server | Response handling', () => {

0 commit comments

Comments
 (0)