glashjs 0.12.0 → 0.12.1
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/package.json +1 -1
- package/src/server/server.mjs +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glashjs",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"description": "glashjs — a web framework built on top of Next.js: file-based routing, SSR, API routes, JSX components with client hydration, nested layouts, streaming SSR, a best-in-class build-time asset optimizer, offline PWA layer, animated favicon, and secure-by-default headers. Zero mandatory dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
package/src/server/server.mjs
CHANGED
|
@@ -131,6 +131,15 @@ async function handleApi(res, mod, req, ctx, secHeaders) {
|
|
|
131
131
|
}
|
|
132
132
|
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) ctx.body = await readJson(req);
|
|
133
133
|
const result = await handler(ctx);
|
|
134
|
+
// Next-style route handlers return a Web `Response` (e.g. Response.json(...)).
|
|
135
|
+
// Pass it through so migrated API routes work unchanged.
|
|
136
|
+
if (typeof Response !== 'undefined' && result instanceof Response) {
|
|
137
|
+
const headers = { ...secHeaders };
|
|
138
|
+
result.headers.forEach((v, k) => { headers[k] = v; });
|
|
139
|
+
const buf = Buffer.from(await result.arrayBuffer());
|
|
140
|
+
res.writeHead(result.status || 200, headers);
|
|
141
|
+
return res.end(buf);
|
|
142
|
+
}
|
|
134
143
|
if (result && result.__response) {
|
|
135
144
|
return send(res, result.status || 200, result.contentType || 'application/json',
|
|
136
145
|
typeof result.body === 'string' ? result.body : JSON.stringify(result.body), { ...secHeaders, ...(result.headers || {}) });
|