@chidchanun/bcp 0.1.6 → 0.1.7
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 +31 -1
- package/README.md +77 -1
- package/docs/server-request-apis.md +404 -0
- package/package.json +6 -1
- package/packages/bundler/src/client-boundary.ts +8 -6
- package/packages/bundler/src/server-production.ts +17 -0
- package/packages/client/src/server.ts +23 -0
- package/packages/server/src/index.ts +32 -13
- package/packages/server/src/request-context.ts +1043 -0
- package/packages/server/src/server-response.ts +82 -0
- package/packages/server/src/standalone-production-runtime-v2.ts +44 -13
|
@@ -41,6 +41,8 @@ import {
|
|
|
41
41
|
DevHmrServer,
|
|
42
42
|
} from "./dev-hmr.js";
|
|
43
43
|
|
|
44
|
+
import { runWithRequestContext, applyResponseCookies } from "./request-context.ts";
|
|
45
|
+
|
|
44
46
|
/*
|
|
45
47
|
* =====================================
|
|
46
48
|
* Constants
|
|
@@ -1441,24 +1443,41 @@ async function handleApiRoute(
|
|
|
1441
1443
|
);
|
|
1442
1444
|
|
|
1443
1445
|
const response =
|
|
1444
|
-
await
|
|
1446
|
+
await runWithRequestContext(
|
|
1445
1447
|
request,
|
|
1448
|
+
|
|
1449
|
+
async () => {
|
|
1450
|
+
const result =
|
|
1451
|
+
await handler(
|
|
1452
|
+
request,
|
|
1453
|
+
{
|
|
1454
|
+
params,
|
|
1455
|
+
}
|
|
1456
|
+
);
|
|
1457
|
+
|
|
1458
|
+
if (
|
|
1459
|
+
!(
|
|
1460
|
+
result instanceof
|
|
1461
|
+
Response
|
|
1462
|
+
)
|
|
1463
|
+
) {
|
|
1464
|
+
throw new Error(
|
|
1465
|
+
`API handler "${method} ${route.pathname}" must return a Response object.`
|
|
1466
|
+
);
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
return applyResponseCookies(
|
|
1470
|
+
result
|
|
1471
|
+
);
|
|
1472
|
+
},
|
|
1446
1473
|
{
|
|
1447
|
-
|
|
1474
|
+
remoteAddress:
|
|
1475
|
+
req.socket
|
|
1476
|
+
.remoteAddress ??
|
|
1477
|
+
null,
|
|
1448
1478
|
}
|
|
1449
1479
|
);
|
|
1450
1480
|
|
|
1451
|
-
if (
|
|
1452
|
-
!(
|
|
1453
|
-
response instanceof
|
|
1454
|
-
Response
|
|
1455
|
-
)
|
|
1456
|
-
) {
|
|
1457
|
-
throw new Error(
|
|
1458
|
-
`API handler "${method} ${route.pathname}" must return a Response object.`
|
|
1459
|
-
);
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1462
1481
|
await sendWebResponse(
|
|
1463
1482
|
res,
|
|
1464
1483
|
response,
|