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
| cookies | `string`| All the cookies of the user |
130
+
| isClient | `boolean` | Useful to know in your contextFactory if you're in the client |
131
+
| pathName | `string`| Current path of the url requested |
132
+
| userAgent | `string`| Information of the browser, device and version in raw |
125
133
126
134
#### createServerContextFactoryParams({ req })
127
135
128
136
Create the params for the contextFactory on the server
129
137
130
138
##### Params
131
139
132
-
Field | Type | Description
133
-
--- | --- | ---
134
-
req | `object` | [Native Node Incoming Message](https://nodejs.org/api/http.html#http_class_http_incomingmessage) with any customized property added on your middleware
| req | `object` | [Native Node Incoming Message](https://nodejs.org/api/http.html#http_class_http_incomingmessage) with any customized property added on your middleware |
135
143
136
144
##### Response
137
145
138
-
Field | Type | Description
139
-
--- | --- | ---
140
-
cookies | `string` | All the cookies of the user
141
-
isClient | `boolean` | Useful to know in your contextFactory if you're in the client
142
-
pathName | `string` | Current path of the url requested
143
-
req | `object` | [Native Node Incoming Message](https://nodejs.org/api/http.html#http_class_http_incomingmessage) with any customized property added on your middleware
144
-
userAgent | `string` | Information of the browser, device and version in raw
| cookies | `string`| All the cookies of the user |
149
+
| isClient | `boolean` | Useful to know in your contextFactory if you're in the client |
150
+
| pathName | `string`| Current path of the url requested |
151
+
| req | `object`| [Native Node Incoming Message](https://nodejs.org/api/http.html#http_class_http_incomingmessage) with any customized property added on your middleware |
152
+
| userAgent | `string`| Information of the browser, device and version in raw |
This method, retrieves the component page with the `getInitialProps` method, executes the async method and when it receives the info, then render to a string using the `Target` component and passing down the `context`.
149
157
150
158
##### Params
151
159
152
-
Field | Type | Description
153
-
--- | --- | ---
154
-
Target | `React Element` | React Element to be used for passing the context and render the app on it.
155
-
context |`object` | Context to be passed to the Target component and to the `getInitialProps`
156
-
renderProps | `object` | Props used by React Router with some useful info. We're extracting the pageComponent from it
| Target | `React Element` | React Element to be used for passing the context and render the app on it. |
163
+
| context | `object`| Context to be passed to the Target component and to the `getInitialProps` |
164
+
| renderProps | `object`| Props used by React Router with some useful info. We're extracting the pageComponent from it |
157
165
158
166
##### Response
159
167
160
168
The response is a promise resolved with two parameters. In addition, you can define an optional `__HTTP__` object in `initialProps` to allow server side redirects using SUI-SSR:
161
169
162
-
Field | Type | Description
163
-
--- | --- | ---
164
-
initialProps | `object` | Result of executing the `getInitialProps` of the pageComponent.
165
-
initialprops.__HTTP__ | `object` | An optional object containing a `redirectTo` key where an url might be included to allow 3XX server side redirects using [sui-ssr]. By default, redirect status code is 301, but you may set a valid `redirectStatusCode` option set in the file `@s-ui/ssr/status-codes`, an optional `httpCookie` key where you will define an object with the key/value of the `Http-Cookie` to be set from server and an optional `headers` key array of objects where you will define a custom response headers (see https://github.com/SUI-Components/sui/tree/master/packages/sui-ssr)
166
-
reactString | `string` | String with the renderized app ready to be sent.
| initialProps | `object` | Result of executing the `getInitialProps` of the pageComponent. |
173
+
| initialprops.**HTTP** | `object` | An optional object containing a `redirectTo` key where an url might be included to allow 3XX server side redirects using [sui-ssr]. By default, redirect status code is 301, but you may set a valid `redirectStatusCode` option set in the file `@s-ui/ssr/status-codes`, an optional `httpCookie` key where you will define an object with the key/value of the `Http-Cookie` to be set from server and an optional `headers` key array of objects where you will define a custom response headers (see https://github.com/SUI-Components/sui/tree/master/packages/sui-ssr) |
174
+
| reactString | `string` | String with the renderized app ready to be sent. |
167
175
168
-
#### loadPage(contextFactory, importPage)
176
+
#### loadPage(importPage, logger?)
169
177
170
-
Load the page asynchronously by using React Router and resolving the getInitialProps. On the client it prepare the component to show the `renderLoading` (if specified) of the component.
178
+
Load the page asynchronously by using React Router and resolving the getInitialProps. On the client it prepare the component to show the `renderLoading` (if specified) of the component. On the server, it wraps `getInitialProps` execution in a try-catch block to prevent crashes.
171
179
172
180
##### Params
173
181
174
-
Field | Type | Description
175
-
--- | --- | ---
176
-
contextFactory | `function` | Context factory method to create the context that will be used on the app.
177
-
importPage | `function` | Import the chunk of the page
| importPage | `function` | Import the chunk of the page |
185
+
| logger | `object` (optional) | Optional logger object with an `error(message: string, error: Error)` method for server-side error logging |
186
+
187
+
##### Error Handling
188
+
189
+
When `getInitialProps` throws an error on the server:
190
+
191
+
- The error is caught, logged using the provided `logger` (if available), and then **re-thrown**.
192
+
- This allows the server's global error handling middleware to catch the exception and manage the response accordingly (e.g., render a 500 page), preventing the SSR process from crashing silently.
0 commit comments