MCPcopy Create free account
hub / github.com/Effect-TS/effect / withStaticFiles

Function withStaticFiles

packages/platform/node/test/HttpStaticServer.test.ts:33–57  ·  view source on GitHub ↗
(
  run: (context: {
    readonly handler: (request: Request) => Promise<Response>
    readonly root: string
    readonly outsideFile: string
  }) => Promise<void>,
  options: Omit<Parameters<typeof HttpStaticServer.make>[0], "root"> = {}
)

Source from the content-addressed store, hash-verified

31 )
32
33const withStaticFiles = async (
34 run: (context: {
35 readonly handler: (request: Request) => Promise<Response>
36 readonly root: string
37 readonly outsideFile: string
38 }) => Promise<void>,
39 options: Omit<Parameters<typeof HttpStaticServer.make>[0], "root"> = {}
40) => {
41 const temporaryRoot = await mkdtemp(NodePath.join(tmpdir(), "effect-http-static-server-"))
42 const root = NodePath.join(temporaryRoot, "root")
43 const outsideFile = NodePath.join(temporaryRoot, NodePath.basename(fixturesOutsideFile))
44
45 await Promise.all([
46 cp(fixturesRoot, root, { recursive: true }),
47 copyFile(fixturesOutsideFile, outsideFile)
48 ])
49
50 const { handler, dispose } = makeHandler(root, options)
51 try {
52 await run({ handler, root, outsideFile })
53 } finally {
54 await dispose()
55 await rm(temporaryRoot, { recursive: true, force: true })
56 }
57}
58
59describe("HttpStaticServer", () => {
60 it("serves files with expected content type and body", async () => {

Callers 1

Calls 6

joinMethod · 0.80
allMethod · 0.80
makeHandlerFunction · 0.70
copyFileFunction · 0.50
runFunction · 0.50
disposeFunction · 0.50

Tested by

no test coverage detected