MCPcopy Create free account
hub / github.com/effect-app/libs / addAll

Function addAll

repos/effect/packages/effect/src/unstable/http/HttpRouter.ts:122–160  ·  view source on GitHub ↗
(
    routes: Routes
  )

Source from the content-addressed store, hash-verified

120 const middleware = new Set<middleware.Fn>()
121
122 const addAll = <const Routes extends ReadonlyArray<Route<any, any>>>(
123 routes: Routes
124 ): Effect.Effect<
125 void,
126 never,
127 | Request.From<"Requires", Exclude<Route.Context<Routes[number]>, Provided>>
128 | Request.From<"Error", Route.Error<Routes[number]>>
129 > =>
130 Effect.contextWith((context: Context.Context<never>) => {
131 const middleware = getMiddleware(context)
132 const applyMiddleware = (effect: Effect.Effect<HttpServerResponse.HttpServerResponse>) => {
133 for (let i = 0; i < middleware.length; i++) {
134 effect = middleware[i](effect)
135 }
136 return effect
137 }
138 for (let i = 0; i < routes.length; i++) {
139 const route = middleware.length === 0 ? routes[i] : makeRoute({
140 ...routes[i],
141 handler: applyMiddleware(routes[i].handler as Effect.Effect<HttpServerResponse.HttpServerResponse>)
142 })
143 if (route.method === "*") {
144 if (route.path.endsWith("/*")) {
145 router.all(route.path, route as any)
146 router.all(route.path.slice(0, -2) as any, route as any)
147 } else {
148 router.all(route.path, route as any)
149 }
150 } else {
151 if (route.path.endsWith("/*")) {
152 router.on(route.method, route.path, route as any)
153 router.on(route.method, route.path.slice(0, -2) as any, route as any)
154 } else {
155 router.on(route.method, route.path, route as any)
156 }
157 }
158 }
159 return Effect.void
160 })
161
162 return HttpRouter.of({
163 [TypeId]: TypeId,

Callers 2

prefixedFunction · 0.70
HttpRouter.tsFile · 0.70

Calls 4

getMiddlewareFunction · 0.85
makeRouteFunction · 0.85
applyMiddlewareFunction · 0.70
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…