@server/next 0.20.38 → 0.20.40
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/getMachine.js +12 -15
- package/src/helpers/handleRequest.js +5 -2
- package/src/index.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@server/next",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.40",
|
|
4
4
|
"description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
|
|
5
5
|
"homepage": "https://server-js.com/",
|
|
6
6
|
"repository": "https://github.com/franciscop/server-next.git",
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
function getProvider() {
|
|
2
|
-
if (
|
|
3
|
-
return null;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
function getService() {
|
|
2
|
+
if (typeof Netlify !== "undefined") return "netlify";
|
|
7
3
|
return null;
|
|
8
4
|
}
|
|
9
5
|
|
|
10
6
|
function getRuntime() {
|
|
11
|
-
if (
|
|
12
|
-
if (
|
|
7
|
+
if (typeof Bun !== "undefined") return "bun";
|
|
8
|
+
if (typeof Deno !== "undefined") return "deno";
|
|
13
9
|
if (globalThis.process?.versions?.node) return "node";
|
|
14
10
|
return null;
|
|
15
11
|
}
|
|
16
12
|
|
|
13
|
+
function getProduction() {
|
|
14
|
+
// Can I cry now?
|
|
15
|
+
if (typeof Netlify !== "undefined")
|
|
16
|
+
return Netlify.env.get("NETLIFY_DEV") !== "true";
|
|
17
|
+
return process.env.NODE_ENV === "production";
|
|
18
|
+
}
|
|
19
|
+
|
|
17
20
|
export default function getMachine() {
|
|
18
|
-
const provider = getProvider();
|
|
19
21
|
return {
|
|
20
|
-
provider,
|
|
21
|
-
service: getService(),
|
|
22
|
+
provider: getProvider(),
|
|
22
23
|
runtime: getRuntime(),
|
|
23
|
-
|
|
24
|
-
production:
|
|
25
|
-
provider === "netlify"
|
|
26
|
-
? Netlify.env.get("NETLIFY_DEV") !== "true"
|
|
27
|
-
: process.env.NODE_ENV === "production",
|
|
24
|
+
production: getProduction(),
|
|
28
25
|
};
|
|
29
26
|
}
|
|
@@ -38,8 +38,11 @@ export default async function handleRequest(handlers, ctx) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// In Netlify, a non-response is perfectly valid, which would indicate
|
|
41
|
-
// the edge function to just go ahead and consume the original resource
|
|
42
|
-
|
|
41
|
+
// the edge function to just go ahead and consume the original resource. But
|
|
42
|
+
// we have already "consumed" the resource, so we can only return the next one
|
|
43
|
+
if (ctx.machine.provider === "netlify") {
|
|
44
|
+
return await ctx.req.context.next();
|
|
45
|
+
}
|
|
43
46
|
|
|
44
47
|
// In other environments, a non-response is wrong and we should 404 then
|
|
45
48
|
return new Response("Not Found", { status: 404 });
|
package/src/index.js
CHANGED
|
@@ -105,6 +105,7 @@ server.prototype.node = async function () {
|
|
|
105
105
|
|
|
106
106
|
// Netlify
|
|
107
107
|
server.prototype.callback = async function (request, context) {
|
|
108
|
+
// Consider simply renaming to "ctx.next()"
|
|
108
109
|
request.context = context;
|
|
109
110
|
try {
|
|
110
111
|
if (typeof Netlify === "undefined") {
|