Crash fixes
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
db.sqlite3
|
||||
dist
|
||||
node_modules
|
||||
storage
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -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"),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
"common": ["./packages/common/src/index.ts"],
|
||||
"common/api": ["./packages/common/src/api.ts"],
|
||||
"common/db": ["./packages/common/src/db.ts"],
|
||||
"make-api": ["./packages/make-api/index.ts"],
|
||||
"make-api": ["./packages/make-api/src/index.ts"],
|
||||
},
|
||||
},
|
||||
"include": ["${configDir}/src"],
|
||||
|
||||
Reference in New Issue
Block a user