diff options
author | 2023-08-18 19:58:03 -0700 | |
---|---|---|
committer | 2023-08-18 19:58:03 -0700 | |
commit | 943a6642243cbc8a180ab7108279dd7110ab1eaf (patch) | |
tree | 3382acb2c41536e942b8bf09f5f9fd4c97e551f8 /src/bun.js/api/filesystem_router.zig | |
parent | d0664f83773fc39b8bd6b9ecdfc52833c7ce6b81 (diff) | |
download | bun-943a6642243cbc8a180ab7108279dd7110ab1eaf.tar.gz bun-943a6642243cbc8a180ab7108279dd7110ab1eaf.tar.zst bun-943a6642243cbc8a180ab7108279dd7110ab1eaf.zip |
Remove most C API usages, add debugger pretty printers for `Headers`, `URLSearchParams`, `FormData`, `Worker`, `EventTarget` (#4187)
* Add pretty printers for `Headers`, `URLSearchParams`, and `FormData`
* [untested] Add way to code generate getInternalProperties
* bump
* Bump Webkit
* Ref the event loop while loaded
* wip
* checkpoint
* another checkpoint
* The code has been written
* Fixup exports
* Fix all the errors
* Fix bug
* [console.log] Fix bug when printing non-reified types missing values
* Fix loading hash table
* fix plugin
* Fix ref & unref
* auto-unref
* various fixes
* Update bun.zig
* Set toStringTag
* Delete code for macro JSX
* Delete code for `bun dev` HTTP JS
* Move Bun.serve to C++ API
* Delete JSC C API code
* :scissors: :skull: code
* Use JSC C++ for `confirm`, `Crypto`, `prompt`, `alert`
* more dead code
* Update exports.zig
* Use JSC C++ API for FFI
* Remove remaining usages
* Remove remaining usages
* Update ffi.ts
* Update InternalModuleRegistryConstants.h
* draw the rest of the owl
* Update webcore.zig
* bind it
* Fix performance regression in crypto.randomUIUD()
* Update js_parser.zig
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/api/filesystem_router.zig')
-rw-r--r-- | src/bun.js/api/filesystem_router.zig | 116 |
1 files changed, 1 insertions, 115 deletions
diff --git a/src/bun.js/api/filesystem_router.zig b/src/bun.js/api/filesystem_router.zig index edb666040..c15826c31 100644 --- a/src/bun.js/api/filesystem_router.zig +++ b/src/bun.js/api/filesystem_router.zig @@ -21,11 +21,10 @@ const JSError = Base.JSError; const JSValue = JSC.JSValue; const JSGlobalObject = JSC.JSGlobalObject; const strings = @import("root").bun.strings; -const NewClass = Base.NewClass; + const To = Base.To; const Request = WebCore.Request; -const FetchEvent = WebCore.FetchEvent; const URLPath = @import("../../http/url_path.zig"); const URL = @import("../../url.zig").URL; const Log = @import("root").bun.logger; @@ -41,117 +40,6 @@ const default_extensions = &[_][]const u8{ "js", }; -const DeprecatedGlobalRouter = struct { - pub fn deprecatedBunGlobalMatch( - _: void, - ctx: js.JSContextRef, - _: js.JSObjectRef, - _: js.JSObjectRef, - arguments: []const js.JSValueRef, - exception: js.ExceptionRef, - ) js.JSObjectRef { - if (arguments.len == 0) { - JSError(getAllocator(ctx), "Expected string, FetchEvent, or Request but there were no arguments", .{}, ctx, exception); - return null; - } - - const arg: JSC.JSValue = brk: { - if (FetchEvent.Class.isLoaded()) { - if (JSValue.as(JSValue.fromRef(arguments[0]), FetchEvent)) |fetch_event| { - if (fetch_event.request_context != null) { - return deprecatedMatchFetchEvent(ctx, fetch_event, exception); - } - - // When disconencted, we still have a copy of the request data in here - break :brk JSC.JSValue.fromRef(fetch_event.getRequest(ctx, null, undefined, null)); - } - } - break :brk JSC.JSValue.fromRef(arguments[0]); - }; - - var router = JavaScript.VirtualMachine.get().bundler.router orelse { - JSError(getAllocator(ctx), "Bun.match needs a framework configured with routes", .{}, ctx, exception); - return null; - }; - - var path_: ?ZigString.Slice = null; - var req_url_slice: ZigString.Slice = .{}; - defer req_url_slice.deinit(); - var pathname: string = ""; - defer { - if (path_) |path| { - path.deinit(); - } - } - - if (arg.isString()) { - var path_string = arg.getZigString(ctx); - path_ = path_string.toSlice(bun.default_allocator); - var url = URL.parse(path_.?.slice()); - pathname = url.pathname; - } else if (arg.as(Request)) |req| { - req_url_slice = req.url.toUTF8(bun.default_allocator); - var url = URL.parse(req_url_slice.slice()); - pathname = url.pathname; - } - - if (path_ == null) { - JSError(getAllocator(ctx), "Expected string, FetchEvent, or Request", .{}, ctx, exception); - return null; - } - - const url_path = URLPath.parse(path_.?.slice()) catch { - JSError(getAllocator(ctx), "Could not parse URL path", .{}, ctx, exception); - return null; - }; - - var match_params_fallback = std.heap.stackFallback(1024, bun.default_allocator); - var match_params_allocator = match_params_fallback.get(); - var match_params = Router.Param.List{}; - match_params.ensureTotalCapacity(match_params_allocator, 16) catch unreachable; - var prev_allocator = router.routes.allocator; - router.routes.allocator = match_params_allocator; - defer router.routes.allocator = prev_allocator; - if (router.routes.matchPage("", url_path, &match_params)) |matched| { - return createRouteObjectFromMatch(ctx, &matched); - } - // router.routes.matchPage - - return JSC.JSValue.jsNull().asObjectRef(); - } - - fn deprecatedMatchFetchEvent( - ctx: js.JSContextRef, - fetch_event: *const FetchEvent, - _: js.ExceptionRef, - ) js.JSObjectRef { - return createRouteObject(ctx, fetch_event.request_context.?); - } - - fn createRouteObject(ctx: js.JSContextRef, req: *const http.RequestContext) js.JSValueRef { - const route = &(req.matched_route orelse { - return js.JSValueMakeNull(ctx); - }); - - return createRouteObjectFromMatch(ctx, route); - } - - fn createRouteObjectFromMatch( - ctx: js.JSContextRef, - route: *const Router.Match, - ) js.JSValueRef { - var matched = MatchedRoute.init( - getAllocator(ctx), - route.*, - JSC.VirtualMachine.get().refCountedString(JSC.VirtualMachine.get().origin.href, null, false), - JSC.VirtualMachine.get().refCountedString(JSC.VirtualMachine.get().bundler.options.routes.asset_prefix_path, null, false), - JSC.VirtualMachine.get().refCountedString(JSC.VirtualMachine.get().bundler.fs.top_level_dir, null, false), - ) catch unreachable; - - return matched.toJS(ctx).asObjectRef(); - } -}; - pub const FileSystemRouter = struct { origin: ?*JSC.RefString = null, base_dir: ?*JSC.RefString = null, @@ -764,5 +652,3 @@ pub const MatchedRoute = struct { return JSValue.createEmptyObject(globalThis, 0); } }; - -pub const deprecatedBunGlobalMatch = DeprecatedGlobalRouter.deprecatedBunGlobalMatch; |