// main.ts
import { HttpRouter, HttpServer, HttpServerResponse } from "@effect/platform";
import { NodeHttpServer, NodeRuntime } from "@effect/platform-node";
import { Layer } from "effect";
import { createServer } from "node:http";
import { getBird } from "./bird.ts";
// Define the router with a single route for the root URL
const router = HttpRouter.empty.pipe(
HttpRouter.get("/hellow", HttpServerResponse.text("Hello World")),
HttpRouter.get("/", HttpServerResponse.json(getBird)),
);
// Set up the application server with logging
const app = router.pipe(HttpServer.serve(), HttpServer.withLogAddress);
// Specify the port
const port = 3000;
// Create a server layer with the specified port
const ServerLive = NodeHttpServer.layer(() => createServer(), { port });
// Run the application
NodeRuntime.runMain(Layer.launch(Layer.provide(app, ServerLive)));
// bird.ts
import { Data, Effect } from "effect";
class HttpMyError extends Data.TaggedError("HttpError")<{}> {}
// ┌─── Effect<never, HttpError, never>
// ▼
// export const getBird = Effect.fail(new HttpMyError());
export const getBird = Effect.succeed({ a: "2", b: "23" });
// main.ts
import { HttpRouter, HttpServer, HttpServerResponse } from "@effect/platform";
import { NodeHttpServer, NodeRuntime } from "@effect/platform-node";
import { Layer } from "effect";
import { createServer } from "node:http";
import { getBird } from "./bird.ts";
// Define the router with a single route for the root URL
const router = HttpRouter.empty.pipe(
HttpRouter.get("/hellow", HttpServerResponse.text("Hello World")),
HttpRouter.get("/", HttpServerResponse.json(getBird)),
);
// Set up the application server with logging
const app = router.pipe(HttpServer.serve(), HttpServer.withLogAddress);
// Specify the port
const port = 3000;
// Create a server layer with the specified port
const ServerLive = NodeHttpServer.layer(() => createServer(), { port });
// Run the application
NodeRuntime.runMain(Layer.launch(Layer.provide(app, ServerLive)));
// bird.ts
import { Data, Effect } from "effect";
class HttpMyError extends Data.TaggedError("HttpError")<{}> {}
// ┌─── Effect<never, HttpError, never>
// ▼
// export const getBird = Effect.fail(new HttpMyError());
export const getBird = Effect.succeed({ a: "2", b: "23" });