-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: cleanup entry points a little
- Loading branch information
Showing
3 changed files
with
31 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,52 @@ | ||
import * as NodeSdk from "@effect/opentelemetry/NodeSdk" | ||
import * as Http from "@effect/platform/HttpServer" | ||
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http" | ||
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base" | ||
import * as Node from "@typed/core/Node" | ||
import { toServerRouter } from "@typed/core/Platform" | ||
import * as Api from "@typed/realworld/api" | ||
import { Live } from "@typed/realworld/api/infrastructure" | ||
import { CurrentUserLive } from "@typed/realworld/api/users/infrastructure" | ||
import { CurrentUserLive, Live } from "@typed/realworld/api/infrastructure" | ||
import * as Ui from "@typed/realworld/ui" | ||
import { ServerResponse, ServerRouter } from "@typed/server" | ||
import { ServerHeaders, ServerResponse, ServerRouter } from "@typed/server" | ||
import { Effect, LogLevel } from "effect" | ||
import sms from "source-map-support" | ||
|
||
// Enable source maps for errors | ||
sms.install() | ||
|
||
// Convert our UI router to a ServerRouter and provide a layout to construct a full HTML document. | ||
toServerRouter(Ui.router, { layout: Ui.document }).pipe( | ||
ServerRouter.catchAll( | ||
(_) => | ||
ServerResponse.empty({ | ||
status: 303, | ||
headers: Http.headers.fromInput({ | ||
location: _._tag === "RedirectError" ? _.path.toString() : "/login" | ||
}) | ||
ServerRouter.catchAll((error) => | ||
ServerResponse.empty({ | ||
status: 303, | ||
headers: ServerHeaders.fromInput({ | ||
location: error._tag === "RedirectError" ? error.path.toString() : "/login" | ||
}) | ||
}) | ||
), | ||
// Mount our API | ||
ServerRouter.mountApp( | ||
"/api", | ||
Effect.catchTag(Api.server, "Unauthorized", () => ServerResponse.empty({ status: 401 })) | ||
), | ||
// Provide all resources which change per-request | ||
Effect.provide(CurrentUserLive), | ||
// Start the server. Integrates with our Vite plugin to serve client assets using Vite for development and | ||
// using a static file server, with gzip support, for production. | ||
Node.listen({ port: 3000, serverDirectory: import.meta.dirname, logLevel: LogLevel.Debug }), | ||
// Provide all static resources which do not change per-request | ||
Effect.provide(Live), | ||
// OpenTelemetry tracing | ||
Effect.provide(NodeSdk.layer(() => ({ | ||
resource: { serviceName: "realworld" }, | ||
spanProcessor: new BatchSpanProcessor( | ||
new OTLPTraceExporter({ | ||
url: "http://localhost:4318/v1/traces" | ||
}) | ||
) | ||
}))), | ||
Effect.provide( | ||
NodeSdk.layer(() => ({ | ||
resource: { serviceName: "realworld" }, | ||
spanProcessor: new BatchSpanProcessor( | ||
new OTLPTraceExporter({ | ||
url: "http://localhost:4318/v1/traces" | ||
}) | ||
) | ||
})) | ||
), | ||
// Kick off the application, capturing SIGINT and SIGTERM to gracefully shutdown the server | ||
// as well as respond to Vite's HMR requests to clean up resources when change occur during development. | ||
Node.run | ||
) |