const get = <A, E, R>(
path: string,
body: (req: Request, res: Response) => Effect.Effect<A, E, R | RequestContext>,
) =>
Effect.gen(function* () {
const app = yield* Express;
const run = yield* FiberSet.makeRuntime<R>();
app.get(path, (req, res) =>
run(
Effect.provideService(body(req, res), RequestContext, {
tenantId: Option.fromNullable(req.header("X-Tenant-Id")),
}),
),
);
});
const IndexRouteLive = Layer.scopedDiscard(
get("/", (_, res) =>
Effect.gen(function* () {
const context = yield* RequestContext;
res.json({
tenantId: context.tenantId,
});
}),
),
);
const get = <A, E, R>(
path: string,
body: (req: Request, res: Response) => Effect.Effect<A, E, R | RequestContext>,
) =>
Effect.gen(function* () {
const app = yield* Express;
const run = yield* FiberSet.makeRuntime<R>();
app.get(path, (req, res) =>
run(
Effect.provideService(body(req, res), RequestContext, {
tenantId: Option.fromNullable(req.header("X-Tenant-Id")),
}),
),
);
});
const IndexRouteLive = Layer.scopedDiscard(
get("/", (_, res) =>
Effect.gen(function* () {
const context = yield* RequestContext;
res.json({
tenantId: context.tenantId,
});
}),
),
);