| 121 | } |
| 122 | |
| 123 | async parse(args: { |
| 124 | request: Request |
| 125 | resolutionContext?: ResponseResolutionContext |
| 126 | }) { |
| 127 | const url = new URL(args.request.url) |
| 128 | const cookies = getAllRequestCookies(args.request) |
| 129 | |
| 130 | /** |
| 131 | * Handle custom predicate functions. |
| 132 | * @note Invoke this during parsing so the user can parse the path parameters |
| 133 | * manually. Otherwise, `params` is always an empty object, which isn't nice. |
| 134 | */ |
| 135 | if (typeof this.info.path === 'function') { |
| 136 | const customPredicateResult = await this.info.path({ |
| 137 | request: args.request, |
| 138 | cookies, |
| 139 | }) |
| 140 | |
| 141 | const match = |
| 142 | typeof customPredicateResult === 'boolean' |
| 143 | ? { |
| 144 | matches: customPredicateResult, |
| 145 | params: {}, |
| 146 | } |
| 147 | : customPredicateResult |
| 148 | |
| 149 | return { |
| 150 | match, |
| 151 | cookies, |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | const match = this.info.path |
| 156 | ? matchRequestUrl(url, this.info.path, args.resolutionContext?.baseUrl) |
| 157 | : { matches: false, params: {} } |
| 158 | |
| 159 | return { |
| 160 | match, |
| 161 | cookies, |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | async predicate(args: { |
| 166 | request: Request |