This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
20 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
import { createFetchHandlerFromDir } from "winterspec/adapters/node" | ||
import { | ||
createFetchHandlerFromDir, | ||
createWinterSpecBundleFromDir, | ||
} from "winterspec/adapters/node" | ||
import { Request as EdgeRuntimeRequest } from "@edge-runtime/primitives" | ||
import type { Middleware } from "winterspec/middleware" | ||
import { join } from "node:path" | ||
import { ZodLevelDatabase } from "api/db/zod-level-db" | ||
import os from "node:os" | ||
import { Middleware } from "winterspec" | ||
|
||
export const startServer = async ({ port }: { port: number }) => { | ||
const db = new ZodLevelDatabase(os.tmpdir() + "/devdb") | ||
|
||
const serverFetch = await createFetchHandlerFromDir( | ||
const winterspecBundle = await createWinterSpecBundleFromDir( | ||
join(import.meta.dir, "../../routes"), | ||
{ | ||
middleware: [ | ||
async (req, ctx, next) => { | ||
;(ctx as any).db = db | ||
) | ||
|
||
const middleware: Middleware[] = [ | ||
async (req: any, ctx: any, next: any) => { | ||
;(ctx as any).db = db | ||
|
||
return next(req, ctx) | ||
}, | ||
], | ||
return next(req, ctx) | ||
}, | ||
) | ||
] | ||
|
||
return Bun.serve({ | ||
const server = Bun.serve({ | ||
fetch: (bunReq) => { | ||
const req = new EdgeRuntimeRequest(bunReq.url, { | ||
headers: bunReq.headers, | ||
method: bunReq.method, | ||
body: bunReq.body, | ||
}) | ||
return serverFetch(req as any) | ||
return winterspecBundle.makeRequest(req as any, { | ||
middleware, | ||
}) | ||
}, | ||
port, | ||
}) | ||
|
||
return server | ||
} |
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