Crash fixes

This commit is contained in:
2024-08-06 22:11:06 +02:00
parent 4210f2168a
commit a5b16cbdf9
6 changed files with 23 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
import { RequestId } from "common";
import { Effect, Exit, Layer, Option as O, pipe, Scope, unsafeCoerce } from "effect";
import { Effect, Exit, Layer, ManagedRuntime, Option as O, pipe, Scope, unsafeCoerce } from "effect";
import { ulid } from "ulid";
import { app } from "./app";
import { DatabaseLive } from "./services/database";
@@ -8,16 +8,11 @@ import { StorageFilesystem } from "./services/storage";
const scope = Effect.runSync(Scope.make());
const layers = pipe(
Layer.merge(
StorageFilesystem("storage"),
pipe(
DatabaseLive(),
Layer.provide(Layer.succeed(Scope.Scope, scope)),
),
),
Layer.memoize,
Effect.provideService(Scope.Scope, scope),
const runtime = pipe(
StorageFilesystem("storage"),
Layer.merge(DatabaseLive()),
Layer.provide(Layer.succeed(Scope.Scope, scope)),
ManagedRuntime.make,
);
const server = Bun.serve({
@@ -50,10 +45,9 @@ const server = Bun.serve({
});
const fiber = pipe(
layers,
Effect.flatMap((layers) => Effect.provide(app, layers)),
app,
Effect.provideService(Request, requestInterface),
Effect.runFork,
runtime.runFork,
);
return new Promise((resolve, reject) => {
@@ -69,6 +63,9 @@ const server = Bun.serve({
});
process.on("SIGINT", () => {
Effect.withFiberRuntime((fiber) => Scope.close(scope, Exit.interrupt(fiber.id())));
Effect.runFork(Effect.gen(function* () {
yield* runtime.disposeEffect;
yield* Scope.close(scope, Exit.void);
}));
server.stop();
});

View File

@@ -62,7 +62,7 @@ export const DatabaseLive = (filePath: string = "db.sqlite3") => Layer.effect(Da
db.exec(`CREATE TABLE IF NOT EXISTS Session (
sessionId TEXT NOT NULL PRIMARY KEY,
userId TEXT NOT NULL REFERENCES User (userId) ON DELETE CASCADE ON UPDATE CASCADE,
expiresAt TEXT NOT NULL,
expiresAt TEXT NOT NULL
)`);
db.exec(`CREATE TABLE IF NOT EXISTS Attachment (

View File

@@ -29,7 +29,7 @@ export default () => {
Effect.orDie,
);
const res = yield* Effect.promise((signal) => fetch("/api/login", {
const res = yield* Effect.promise((signal) => fetch("http://localhost:3000/login", {
method: "POST",
body: requestJson,
headers: { "Content-Type": "application/json" },

View File

@@ -1,6 +1,13 @@
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
import path from "node:path";
/** @type {import("vite").UserConfig} */
export default {
plugins: [vanillaExtractPlugin()],
resolve: {
alias: {
"common": path.resolve(__dirname, "../common/src"),
"make-api": path.resolve(__dirname, "../make-api/src"),
},
},
};