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

Function withStaticFiles

packages/platform/node/test/HttpStaticServer.test.ts:40–64  ·  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.layer>[0], "root"> = {}
)

Source from the content-addressed store, hash-verified

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

Callers 1

Calls 6

makeHandlerFunction · 0.70
allMethod · 0.65
copyFileFunction · 0.50
runFunction · 0.50
disposeFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected