mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
types: Bun.serve routes supportes Bun.file's (#20919)
This commit is contained in:
8
packages/bun-types/bun.d.ts
vendored
8
packages/bun-types/bun.d.ts
vendored
@@ -3510,7 +3510,13 @@ declare module "bun" {
|
||||
[K in HTTPMethod]?: RouteHandlerWithWebSocketUpgrade<T>;
|
||||
};
|
||||
|
||||
type RouteValue<T extends string> = Response | false | RouteHandler<T> | RouteHandlerObject<T> | HTMLBundle;
|
||||
type RouteValue<T extends string> =
|
||||
| Response
|
||||
| false
|
||||
| RouteHandler<T>
|
||||
| RouteHandlerObject<T>
|
||||
| HTMLBundle
|
||||
| BunFile;
|
||||
type RouteValueWithWebSocketUpgrade<T extends string> =
|
||||
| RouteValue<T>
|
||||
| RouteHandlerWithWebSocketUpgrade<T>
|
||||
|
||||
0
test/integration/bun-types/fixture/html.html
Normal file
0
test/integration/bun-types/fixture/html.html
Normal file
@@ -5,6 +5,7 @@ import { expect, test as it } from "bun:test";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import { join } from "node:path";
|
||||
import html from "./html.html";
|
||||
import { expectType } from "./utilities";
|
||||
|
||||
// XXX: importing this from "harness" caused a failure in bun-types.test.ts
|
||||
@@ -457,6 +458,26 @@ test({
|
||||
},
|
||||
});
|
||||
|
||||
const files = {} as Record<string, Bun.BunFile>;
|
||||
|
||||
test({
|
||||
routes: {
|
||||
"/this/:test": Bun.file(import.meta.file),
|
||||
"/index.test-d.ts": Bun.file("index.test-d.ts"),
|
||||
// @ts-expect-error this is invalid
|
||||
"/index.test-d.ts.2": () => Bun.file("index.test-d.ts"),
|
||||
"/ping": new Response("pong"),
|
||||
"/": html,
|
||||
// @ts-expect-error this is invalid, but hopefully not for too long
|
||||
"/index.html": new Response(html),
|
||||
...files,
|
||||
},
|
||||
|
||||
fetch: (req, server) => {
|
||||
return new Response("cool");
|
||||
},
|
||||
});
|
||||
|
||||
test({
|
||||
fetch(req, server) {
|
||||
server.upgrade(req);
|
||||
|
||||
Reference in New Issue
Block a user