Add basic http router
Update api
This commit is contained in:
parent
3f78eb1a32
commit
b24ced7bc9
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@
|
||||
!devenv.nix
|
||||
!devenv.yaml
|
||||
!docker-compose.yml
|
||||
!biome.json
|
||||
|
||||
!api/
|
||||
!api/package.json
|
||||
|
@ -1 +0,0 @@
|
||||
console.log("Hello via Bun!");
|
49
api/src/index.ts
Normal file
49
api/src/index.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import {
|
||||
HttpApi,
|
||||
HttpApiBuilder,
|
||||
HttpApiEndpoint,
|
||||
HttpApiGroup,
|
||||
} from "@effect/platform";
|
||||
import { BunHttpServer, BunRuntime } from "@effect/platform-bun";
|
||||
import { Console, Context, Effect, Layer, Schema } from "effect";
|
||||
|
||||
const MyApi = HttpApi.make("MyAPI").add(
|
||||
HttpApiGroup.make("Greetings")
|
||||
.add(HttpApiEndpoint.get("hello-world")`/`.addSuccess(Schema.String))
|
||||
.add(HttpApiEndpoint.get("hello-failure")`/fail`.addError(Schema.String)),
|
||||
);
|
||||
|
||||
class UsersRepository extends Context.Tag("UsersRepository")<
|
||||
UsersRepository,
|
||||
{
|
||||
readonly findById: (id: number) => Effect.Effect<string>;
|
||||
}
|
||||
>() {}
|
||||
|
||||
// const repo = UsersRepository.of({ findById: (id) => Effect.succeed(`${id}`) });
|
||||
|
||||
const GreetingsLive = HttpApiBuilder.group(MyApi, "Greetings", (handlers) =>
|
||||
handlers
|
||||
.handle("hello-world", () =>
|
||||
Effect.gen(function* () {
|
||||
const repository = yield* UsersRepository;
|
||||
yield* Console.log("<- Hello World handler invoked");
|
||||
return yield* repository.findById(42);
|
||||
}),
|
||||
)
|
||||
.handle("hello-failure", () => Effect.fail("Hello fail")),
|
||||
);
|
||||
|
||||
const MyApiLive = HttpApiBuilder.api(MyApi).pipe(Layer.provide(GreetingsLive));
|
||||
|
||||
const userRepoLive = Layer.succeed(UsersRepository, {
|
||||
findById: (id) => Effect.succeed(`${id}`),
|
||||
});
|
||||
|
||||
const ServerLive = HttpApiBuilder.serve().pipe(
|
||||
Layer.provide(MyApiLive),
|
||||
Layer.provide(BunHttpServer.layer({ port: 3000 })),
|
||||
Layer.provide(userRepoLive),
|
||||
);
|
||||
|
||||
Layer.launch(ServerLive).pipe(BunRuntime.runMain);
|
0
api/src/services/auth.ts
Normal file
0
api/src/services/auth.ts
Normal file
42
biome.json
Normal file
42
biome.json
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"$schema": "https://biomejs.dev/schemas/2.1.2/schema.json",
|
||||
"vcs": {
|
||||
"enabled": false,
|
||||
"clientKind": "git",
|
||||
"useIgnoreFile": false
|
||||
},
|
||||
"files": {
|
||||
"ignoreUnknown": false
|
||||
},
|
||||
"formatter": {
|
||||
"enabled": true,
|
||||
"indentStyle": "tab"
|
||||
},
|
||||
"linter": {
|
||||
"enabled": true,
|
||||
"rules": {
|
||||
"recommended": true,
|
||||
"correctness": {
|
||||
"noUnusedImports": {
|
||||
"level": "warn",
|
||||
"fix": "safe",
|
||||
"options": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"javascript": {
|
||||
"formatter": {
|
||||
"quoteStyle": "double",
|
||||
"semicolons": "always"
|
||||
}
|
||||
},
|
||||
"assist": {
|
||||
"enabled": true,
|
||||
"actions": {
|
||||
"source": {
|
||||
"organizeImports": "on"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user