@server/next 0.20.24 → 0.20.26
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/helpers/handleRequest.js +2 -1
- package/src/helpers/validate.js +2 -2
- package/src/index.js +1 -4
- package/src/polyfill.js +11 -0
package/package.json
CHANGED
|
@@ -12,11 +12,12 @@ export default async function handleRequest(handlers, ctx) {
|
|
|
12
12
|
define(ctx.url, "params", () => match);
|
|
13
13
|
|
|
14
14
|
for (let cb of cbs) {
|
|
15
|
-
validate(ctx, cb);
|
|
16
15
|
if (typeof cb === "function") {
|
|
17
16
|
const res = await cb(ctx);
|
|
18
17
|
const out = await parseResponse(res, ctx);
|
|
19
18
|
if (out) return out;
|
|
19
|
+
} else {
|
|
20
|
+
validate(ctx, cb);
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
|
package/src/helpers/validate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import StatusError from "./StatusError.js";
|
|
2
2
|
|
|
3
|
-
export default function (ctx, schema) {
|
|
3
|
+
export default function validate(ctx, schema) {
|
|
4
4
|
if (!schema || typeof schema !== "object") return;
|
|
5
5
|
|
|
6
6
|
let base;
|
|
@@ -22,7 +22,7 @@ export default function (ctx, schema) {
|
|
|
22
22
|
schema.query.parse(ctx.url.query || {});
|
|
23
23
|
}
|
|
24
24
|
} catch (error) {
|
|
25
|
-
if (error.constructor.name === "ZodError") {
|
|
25
|
+
if (error.name === "ZodError" || error.constructor.name === "ZodError") {
|
|
26
26
|
const message = error.issues
|
|
27
27
|
.map(({ path, message }) => `[${base}.${path.join(".")}]: ${message}`)
|
|
28
28
|
.sort()
|
package/src/index.js
CHANGED
|
@@ -174,11 +174,8 @@ export default function server(options = {}) {
|
|
|
174
174
|
options = validateOptions(options, Netlify.env.toObject());
|
|
175
175
|
const ctx = await createWinterContext(request, options, this);
|
|
176
176
|
extendWithDefaults(ctx);
|
|
177
|
-
|
|
178
|
-
console.log(out);
|
|
179
|
-
return out;
|
|
177
|
+
return await handleRequest(this.handlers, ctx);
|
|
180
178
|
} catch (error) {
|
|
181
|
-
console.error(error);
|
|
182
179
|
return new Response(error.message, { status: error.status || 500 });
|
|
183
180
|
}
|
|
184
181
|
};
|
package/src/polyfill.js
CHANGED
|
@@ -4,3 +4,14 @@ if (typeof Response === "undefined") {
|
|
|
4
4
|
return { body, ...other };
|
|
5
5
|
};
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
// Polyfill Netlify's environment variables
|
|
9
|
+
if (typeof Netlify !== "undefined") {
|
|
10
|
+
if (!global.process) {
|
|
11
|
+
global.process = {};
|
|
12
|
+
}
|
|
13
|
+
if (!global.process.env) {
|
|
14
|
+
global.process.env = {};
|
|
15
|
+
}
|
|
16
|
+
Object.assign(global.process.env, Netlify.env.toObject());
|
|
17
|
+
}
|