Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 5145dea

Browse files
committed
Add signal option for std server
1 parent ffea32e commit 5145dea

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

server/stdserver.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { serve as stdServe, serveTLS } from 'https://deno.land/[email protected]/http/server.ts'
1+
import { serve as stdServe, serveTLS, Server as StdServer } from 'https://deno.land/[email protected]/http/server.ts'
22
import log from '../shared/log.ts'
33
import type { ServerRequest } from '../types.ts'
44
import { Application } from './app.ts'
@@ -18,17 +18,15 @@ export type ServeOptions = {
1818
certFile?: string
1919
/** Server public key file. */
2020
keyFile?: string
21+
/* The signal to close the server. */
22+
signal?: AbortSignal
2123
}
2224

2325
/** Create a standard Aleph server. */
24-
export async function serve({ app, port, hostname, certFile, keyFile }: ServeOptions) {
26+
export async function serve({ app, port, hostname, certFile, keyFile, signal }: ServeOptions) {
2527
const server = new Server(app)
2628
await app.ready
2729

28-
if (!app.isDev && app.config.compress) {
29-
await compress.init()
30-
}
31-
3230
while (true) {
3331
try {
3432
let s: AsyncIterable<ServerRequest>
@@ -37,6 +35,12 @@ export async function serve({ app, port, hostname, certFile, keyFile }: ServeOpt
3735
} else {
3836
s = stdServe({ port, hostname })
3937
}
38+
signal?.addEventListener('abort', () => {
39+
(s as StdServer).close()
40+
})
41+
if (!app.isDev && app.config.compress) {
42+
await compress.init()
43+
}
4044
log.info(`Server ready on http://${hostname || 'localhost'}:${port}${app.config.basePath}`)
4145
for await (const r of s) {
4246
server.handle(r)

0 commit comments

Comments
 (0)