Initial version #1
@@ -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",
|
||||||
|
|||||||
10
packages/server/src/config/ServerConfig.ts
Normal file
10
packages/server/src/config/ServerConfig.ts
Normal 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)
|
||||||
1
packages/server/src/config/index.ts
Normal file
1
packages/server/src/config/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * as ServerConfig from "./ServerConfig"
|
||||||
0
packages/server/src/entrypoint.bun.ts
Normal file
0
packages/server/src/entrypoint.bun.ts
Normal file
18
packages/server/src/http.ts
Normal file
18
packages/server/src/http.ts
Normal 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,
|
||||||
|
)
|
||||||
@@ -1 +0,0 @@
|
|||||||
console.log("Hello via Bun!");
|
|
||||||
23
packages/server/src/server.ts
Normal file
23
packages/server/src/server.ts
Normal 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,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user