You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/content/docs/core/routing.mdx
+21-10Lines changed: 21 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,7 +28,6 @@ export default defineApp([
28
28
---
29
29
The`defineApp`function takes an array of middleware and route handlers that are executed in the order they are defined. In this example the request is passed through two middleware functions before being "matched" by the route handlers.
For the `/blog/:slug/edit` route, the `isAuthenticated` function will be executed first, if the user is not authenticated, the response will be a 401 Unauthorized. If the user is authenticated, the `EditBlogPage` component will be rendered. Therefore the flow is interrupted. The `isAuthenticated` function can be shared across multiple routes.
130
127
---
131
-
```
132
128
133
129
## Middleware & Context
134
130
@@ -170,7 +166,6 @@ The context object:
170
166
- if the user is authenticated the request will be passed to the next request handler and `"Hello {ctx.user.username}!"` will be returned
171
167
172
168
---
173
-
```
174
169
175
170
## Documents
176
171
@@ -194,7 +189,6 @@ This component will be rendered on the server side when the page loads. When def
194
189
* Your application's stylesheets and scripts
195
190
* A mount point for your page content (`id="root"` in the code below): this is where your actual page will be rendered - the "dynamic stuff" which updates using React Server Components.
196
191
---
197
-
```
198
192
199
193
```tsxtitle="src/pages/Document.tsx"mark={7}
200
194
exportconst Document = ({ children }) => (
@@ -223,15 +217,32 @@ The `requestInfo` object is available in server functions and provides access to
223
217
import { requestInfo } from"rwsdk/worker";
224
218
225
219
exportasyncfunction myServerFunction() {
226
-
const { request, headers, ctx } = requestInfo;
227
-
// Use request, headers, or ctx as needed
220
+
const { request, response, ctx } =requestInfo;
221
+
// Use request, response, or ctx as needed
228
222
}
229
223
```
230
224
231
225
The `requestInfo` object contains:
232
226
233
-
-`request`: TheincomingHTTPRequestobject
234
-
-`headers`: Responseheaders
227
+
-`request`: The incoming HTTP [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object
228
+
-`response`: A [ResponseInit](https://fetch.spec.whatwg.org/#responseinit) object used to configure the status and headers of the response
235
229
-`ctx`: The app context (same as what's passed to components)
236
230
-`rw`: RedwoodSDK-specific context
237
231
-`cf`: Cloudflare's Execution Context API
232
+
233
+
You can mutate the `response` object to configure the status and headers. For example:
234
+
235
+
```tsx
236
+
import { route } from"rwsdk/router";
237
+
238
+
const NotFound = () => <div>Not Found</div>;
239
+
240
+
route('/some-resource', async ({ response }) => {
241
+
// some logic to determine if the resource is not found
Copy file name to clipboardExpand all lines: docs/src/content/docs/reference/sdk-worker.mdx
+5-9Lines changed: 5 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,12 +83,8 @@ export default defineApp([
83
83
84
84
The `requestInfo` object is used to get information about the current request. It's a singleton that's populated for each request, and constains the following information.
85
85
86
-
```ts
87
-
import { requestInfo } from"rwsdk/worker";
88
-
89
-
requestInfo.request.url;
90
-
requestInfo.request.method;
91
-
requestInfo.request.body;
92
-
requestInfo.ctx;
93
-
requestInfo.headers;
94
-
```
86
+
-`request`: The incoming HTTP [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) object
87
+
-`response`: A [ResponseInit](https://fetch.spec.whatwg.org/#responseinit) object used to configure the status and headers of the response
88
+
-`ctx`: The app context (same as what's passed to components)
0 commit comments