Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ const ctxLog = Output.scoped(.RequestContext, false);
const S3 = bun.S3;
const SocketAddress = @import("bun/socket.zig").SocketAddress;

const bun_docs_url = "https://bun.sh/docs";

const BlobFileContentResult = struct {
data: [:0]const u8,

Expand Down Expand Up @@ -1674,7 +1676,16 @@ pub const ServerConfig = struct {

if (try arg.getTruthy(global, "fetch")) |onRequest_| {
if (!onRequest_.isCallable()) {
return global.throwInvalidArguments("Expected fetch() to be a function", .{});
if (onRequest_.isUndefined()) {
return global.throwInvalidArguments(
"Bun.serve() requires a fetch() function to handle incoming requests. For more information, see " ++ bun_docs_url ++ "api/http#bun-serve",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought that we should accept routes and/or fetch, so this error message isn't exactly right.

also getTruthy avoids undefined already so this is not going to be hit

.{},
);
} else {
const ty = try global.determineSpecificType(onRequest_);
defer ty.deref();
return global.throwInvalidArguments("Expected 'fetch()' to be a function, got {s}", .{ty});
}
}
const onRequest = onRequest_.withAsyncContextIfNeeded(global);
JSC.C.JSValueProtect(global, onRequest.asObjectRef());
Expand Down