MCPcopy
hub / github.com/Effect-TS/effect / make

Function make

packages/platform-node/src/internal/httpServer.ts:41–119  ·  view source on GitHub ↗
(
  evaluate: LazyArg<Http.Server>,
  options: Net.ListenOptions
)

Source from the content-addressed store, hash-verified

39
40/** @internal */
41export const make = (
42 evaluate: LazyArg<Http.Server>,
43 options: Net.ListenOptions
44): Effect.Effect<Server.HttpServer, Error.ServeError, Scope.Scope> =>
45 Effect.gen(function*() {
46 const scope = yield* Effect.scope
47 const server = yield* Effect.acquireRelease(
48 Effect.sync(evaluate),
49 (server) =>
50 Effect.async<void>((resume) => {
51 if (!server.listening) {
52 return resume(Effect.void)
53 }
54 server.close((error) => {
55 if (error) {
56 resume(Effect.die(error))
57 } else {
58 resume(Effect.void)
59 }
60 })
61 })
62 )
63
64 yield* Effect.async<void, Error.ServeError>((resume) => {
65 function onError(cause: Error) {
66 resume(Effect.fail(new Error.ServeError({ cause })))
67 }
68 server.on("error", onError)
69 server.listen(options, () => {
70 server.off("error", onError)
71 resume(Effect.void)
72 })
73 })
74
75 const address = server.address()!
76
77 const wss = yield* pipe(
78 Effect.acquireRelease(
79 Effect.sync(() => new WS.WebSocketServer({ noServer: true })),
80 (wss) =>
81 Effect.async<void>((resume) => {
82 wss.close(() => resume(Effect.void))
83 })
84 ),
85 Scope.extend(scope),
86 Effect.cached
87 )
88
89 return Server.make({
90 address: typeof address === "string" ?
91 {
92 _tag: "UnixAddress",
93 path: address
94 } :
95 {
96 _tag: "TcpAddress",
97 hostname: address.address === "::" ? "0.0.0.0" : address.address,
98 port: address.port

Callers 5

layerServerFunction · 0.70
layerFunction · 0.70
layerConfigFunction · 0.70
layerFunction · 0.50
terminal.tsFile · 0.50

Calls 10

makeUpgradeHandlerFunction · 0.85
syncMethod · 0.80
makeHandlerFunction · 0.70
pipeMethod · 0.65
closeMethod · 0.65
dieMethod · 0.65
makeMethod · 0.65
addFinalizerMethod · 0.65
resumeFunction · 0.50
pipeFunction · 0.50

Tested by

no test coverage detected