Initial version #1

Merged
Thilawyn merged 25 commits from base-project into master 2025-09-18 01:26:10 +02:00
7 changed files with 53 additions and 2 deletions
Showing only changes of commit c0df42c9a9 - Show all commits

View File

@@ -2,7 +2,7 @@
"name": "@website/server", "name": "@website/server",
"private": true, "private": true,
"type": "module", "type": "module",
"module": "./src/index.ts", "module": "./src/entrypoint.bun.ts",
"dependencies": { "dependencies": {
"@effect/platform": "^0.90.8", "@effect/platform": "^0.90.8",
"@effect/platform-bun": "^0.79.0", "@effect/platform-bun": "^0.79.0",

View File

@@ -0,0 +1,10 @@
import { Config, Schema } from "effect"
export const mode = Schema.Config("NODE_ENV",
Schema.compose(Schema.String, Schema.Literal("development", "production"))
).pipe(
Config.withDefault("development")
)
export const httpPort = Config.withDefault(Config.port("SERVER_HTTP_PORT"), 80)

View File

@@ -0,0 +1 @@
export * as ServerConfig from "./ServerConfig"

View File

View File

@@ -0,0 +1,18 @@
import { HttpMiddleware, HttpRouter, HttpServer } from "@effect/platform"
import { Effect, flow, Layer } from "effect"
import { ServerConfig } from "./config"
const router = HttpRouter.empty
export const HttpAppLive = ServerConfig.mode.pipe(
Effect.map(mode => HttpRouter.empty.pipe(
HttpServer.serve(flow(
HttpMiddleware.logger,
HttpMiddleware.xForwardedHeaders,
)),
HttpServer.withLogAddress,
)),
Layer.unwrapEffect,
)

View File

@@ -1 +0,0 @@
console.log("Hello via Bun!");

View File

@@ -0,0 +1,23 @@
import { Effect, flow, Layer, Match } from "effect"
import { ServerConfig } from "./config"
import { HttpAppLive } from "./http"
const ServerDevelopment = Layer.empty.pipe(
Layer.provideMerge(HttpAppLive),
)
const ServerProduction = Layer.empty.pipe(
Layer.provideMerge(HttpAppLive),
)
export const Server = ServerConfig.mode.pipe(
Effect.map(flow(
Match.value,
Match.when("development", () => ServerDevelopment),
Match.when("production", () => ServerProduction),
Match.exhaustive,
)),
Layer.unwrapEffect,
)