-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use Deno.serve() instead of serve()
`serve()` was removed in Deno v1 (May 2020). Release notes: https://github.com/denoland/deno/releases/v1.0.0 Related: #17 Note: the `abort` signal listener was removed because it is always triggered, even when the response is successfully sent See also: denoland/deno#27005
- Loading branch information
1 parent
ea31859
commit 5a27581
Showing
15 changed files
with
52 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ A clear and concise description of what the bug is. | |
**To Reproduce** | ||
|
||
```ts | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { Server } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const io = new Server(); | ||
|
@@ -28,7 +27,8 @@ io.on("connection", (socket) => { | |
}); | ||
}); | ||
|
||
await serve(io.handler(), { | ||
Deno.serve({ | ||
handler: io.handler(), | ||
port: 3000, | ||
}); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ Related issue or discussion: | |
**New behavior** | ||
|
||
```ts | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { Server } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const io = new Server(); | ||
|
@@ -26,7 +25,8 @@ io.on("connection", (socket) => { | |
}); | ||
}); | ||
|
||
await serve(io.handler(), { | ||
Deno.serve({ | ||
handler: io.handler(), | ||
port: 3000, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ Table of content: | |
## Usage | ||
|
||
```ts | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { Server } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
const io = new Server(); | ||
|
@@ -39,7 +38,8 @@ io.on("connection", (socket) => { | |
}); | ||
}); | ||
|
||
await serve(io.handler(), { | ||
Deno.serve({ | ||
handler: io.handler(), | ||
port: 3000, | ||
}); | ||
``` | ||
|
@@ -86,7 +86,6 @@ You need to use the [.handle()](https://github.com/oakserver/oak#handle-method) | |
method: | ||
|
||
```ts | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { Server } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { Application } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
|
@@ -112,7 +111,8 @@ const handler = io.handler(async (req) => { | |
return await app.handle(req) || new Response(null, { status: 404 }); | ||
}); | ||
|
||
await serve(handler, { | ||
Deno.serve({ | ||
handler, | ||
port: 3000, | ||
}); | ||
``` | ||
|
@@ -281,7 +281,6 @@ servers. | |
Documentation: https://socket.io/docs/v4/redis-adapter/ | ||
|
||
```js | ||
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { | ||
createRedisAdapter, | ||
createRedisClient, | ||
|
@@ -301,7 +300,8 @@ const io = new Server({ | |
adapter: createRedisAdapter(pubClient, subClient), | ||
}); | ||
|
||
await serve(io.handler(), { | ||
Deno.serve({ | ||
handler: io.handler(), | ||
port: 3000, | ||
}); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
export { | ||
type ConnInfo, | ||
type Handler, | ||
} from "https://deno.land/[email protected]/http/server.ts"; | ||
|
||
export { getLogger } from "https://deno.land/[email protected]/log/mod.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/** | ||
* @example | ||
* import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
* import { Server } from "https://deno.land/x/[email protected]/mod.ts"; | ||
* | ||
* const io = new Server(); | ||
|
@@ -21,7 +20,8 @@ | |
* }); | ||
* }); | ||
* | ||
* await serve(io.handler(), { | ||
* Deno.serve({ | ||
* handler: io.handler(), | ||
* port: 3000, | ||
* }); | ||
*/ | ||
|
@@ -40,7 +40,6 @@ export { | |
* Documentation: https://socket.io/docs/v4/redis-adapter/ | ||
* | ||
* @example | ||
* import { serve } from "https://deno.land/std/http/server.ts"; | ||
* import { Server, createRedisAdapter, createRedisClient } from "https://deno.land/x/socket_io/mod.ts"; | ||
* | ||
* const [pubClient, subClient] = await Promise.all([ | ||
|
@@ -56,8 +55,9 @@ export { | |
* adapter: createRedisAdapter(pubClient, subClient) | ||
* }); | ||
* | ||
* await serve(io.handler(), { | ||
* port: 3000 | ||
* Deno.serve({ | ||
* handler: io.handler(), | ||
* port: 3000 | ||
* }); | ||
*/ | ||
export { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import { Server, Socket } from "../../socket.io/mod.ts"; | |
import { createPartialDone, runHandshake, waitFor } from "../../util.test.ts"; | ||
import { connect } from "../../../vendor/deno.land/x/[email protected]/mod.ts"; | ||
import { createAdapter } from "../mod.ts"; | ||
import { serve } from "../../../test_deps.ts"; | ||
|
||
function createRedisClient() { | ||
return connect({ | ||
|
@@ -29,7 +28,8 @@ function createServer(port: number): Promise<TestServer> { | |
|
||
const abortController = new AbortController(); | ||
|
||
return serve(io.handler(), { | ||
return Deno.serve({ | ||
handler: io.handler(), | ||
port, | ||
signal: abortController.signal, | ||
onListen: async () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { | |
EventParams, | ||
EventsMap, | ||
} from "../../event-emitter/mod.ts"; | ||
import { getLogger, type Handler } from "../../../deps.ts"; | ||
import { getLogger } from "../../../deps.ts"; | ||
import { Client } from "./client.ts"; | ||
import { Decoder, Encoder } from "../../socket.io-parser/mod.ts"; | ||
import { Namespace, NamespaceReservedEvents } from "./namespace.ts"; | ||
|
@@ -75,7 +75,6 @@ type ParentNspNameMatchFn = ( | |
* Represents a Socket.IO server. | ||
* | ||
* @example | ||
* import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
* import { Server } from "https://deno.land/x/[email protected]/mod.ts"; | ||
* | ||
* const io = new Server(); | ||
|
@@ -96,7 +95,8 @@ type ParentNspNameMatchFn = ( | |
* }); | ||
* }); | ||
* | ||
* await serve(io.handler(), { | ||
* Deno.serve({ | ||
* handler: io.handler(), | ||
* port: 3000, | ||
* }); | ||
*/ | ||
|
@@ -183,18 +183,18 @@ export class Server< | |
* Returns a request handler. | ||
* | ||
* @example | ||
* import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
* import { Server } from "https://deno.land/x/[email protected]/mod.ts"; | ||
* | ||
* const io = new Server(); | ||
* | ||
* await serve(io.handler(), { | ||
* Deno.serve({ | ||
* handler: io.handler(), | ||
* port: 3000, | ||
* }); | ||
* | ||
* @param additionalHandler - another handler which will receive the request if the path does not match | ||
*/ | ||
public handler(additionalHandler?: Handler) { | ||
public handler(additionalHandler?: Deno.ServeHandler) { | ||
return this.engine.handler(additionalHandler); | ||
} | ||
|
||
|
@@ -296,21 +296,21 @@ export class Server< | |
* Closes the server. | ||
* | ||
* @example | ||
* import { serve } from "https://deno.land/[email protected]/http/server.ts"; | ||
* import { Server } from "https://deno.land/x/[email protected]/mod.ts"; | ||
* | ||
* const io = new Server(); | ||
* const abortController = new AbortController(); | ||
* | ||
* await serve(io.handler(), { | ||
* Deno.serve({ | ||
* handler: io.handler(), | ||
* port: 3000, | ||
* signal: abortController.signal, | ||
* onListen: () => { | ||
* setTimeout(() => { | ||
* // close the HTTP server | ||
* abortController.abort(); | ||
* // close the Socket.IO server | ||
* server.close(); | ||
* io.close(); | ||
* }, 10000); | ||
* } | ||
* }); | ||
|
Oops, something went wrong.