@torpor/build 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/state.d.ts +1 -1
- package/package.json +1 -1
- package/src/site/serverEntry.ts +12 -4
- package/src/types/PageState.ts +1 -1
package/CHANGELOG.md
CHANGED
package/dist/state.d.ts
CHANGED
package/package.json
CHANGED
package/src/site/serverEntry.ts
CHANGED
|
@@ -162,7 +162,7 @@ async function loadView(
|
|
|
162
162
|
params: Record<string, string>,
|
|
163
163
|
template: string,
|
|
164
164
|
formStatus?: number,
|
|
165
|
-
form?: Record<string, string>,
|
|
165
|
+
form?: Record<string, string | number>,
|
|
166
166
|
) {
|
|
167
167
|
// There must be a client endpoint with a component
|
|
168
168
|
const clientEndPoint: PageEndPoint | undefined = (await handler.endPoint()).default;
|
|
@@ -330,11 +330,19 @@ async function runAction(
|
|
|
330
330
|
// TODO: do not re-run hooks?
|
|
331
331
|
const newUrl = new URL(url.pathname, url);
|
|
332
332
|
const formStatus = result?.status;
|
|
333
|
-
|
|
334
|
-
|
|
333
|
+
const formMessage = await result?.text();
|
|
334
|
+
if (formMessage && result?.headers.get("Content-Type")?.includes("application/json")) {
|
|
335
|
+
$page.form = JSON.parse(formMessage);
|
|
335
336
|
} else {
|
|
336
|
-
$page.form =
|
|
337
|
+
$page.form = {};
|
|
337
338
|
}
|
|
339
|
+
// Set status and message if they haven't already been set,
|
|
340
|
+
// which means that you can just return e.g. forbidden() or
|
|
341
|
+
// forbidden("no!") and there will be something you can work
|
|
342
|
+
// with in your component, or you can set a completely custom
|
|
343
|
+
// object with whatever info you need
|
|
344
|
+
$page.form!.status ??= formStatus ?? 0;
|
|
345
|
+
$page.form!.message ??= formMessage ?? "";
|
|
338
346
|
return await loadView(ev, newUrl, handler, params, template, formStatus, $page.form);
|
|
339
347
|
} else {
|
|
340
348
|
// If the form was submitted without javascript and there was a
|