@vercel/backends 0.7.1 → 0.8.0
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/dist/dev/cron-host.d.mts +1 -0
- package/dist/dev/cron-host.mjs +51 -0
- package/dist/index.mjs +635 -631
- package/package.json +3 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
|
|
4
|
+
//#region src/dev/cron-host.ts
|
|
5
|
+
const SHIM_ABS = process.env.__VC_DISPATCH_SHIM_ABS;
|
|
6
|
+
const PORT = process.env.__VC_PORT;
|
|
7
|
+
function bail(message) {
|
|
8
|
+
console.error(`[vercel-backends-cron-host] ${message}`);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
if (!SHIM_ABS) bail("missing __VC_DISPATCH_SHIM_ABS");
|
|
12
|
+
if (!PORT) bail("missing __VC_PORT");
|
|
13
|
+
const port = Number.parseInt(PORT, 10);
|
|
14
|
+
if (!Number.isFinite(port) || port <= 0) bail(`invalid __VC_PORT: ${PORT}`);
|
|
15
|
+
async function main() {
|
|
16
|
+
const handler = (await import(pathToFileURL(SHIM_ABS).href)).default;
|
|
17
|
+
if (typeof handler !== "function") bail(`shim at ${SHIM_ABS} did not export a default function (got ${typeof handler})`);
|
|
18
|
+
const server = createServer((req, res) => {
|
|
19
|
+
Promise.resolve(handler(req, res)).catch((err) => {
|
|
20
|
+
console.error(err);
|
|
21
|
+
if (!res.headersSent) {
|
|
22
|
+
res.statusCode = 500;
|
|
23
|
+
res.setHeader("content-type", "application/json");
|
|
24
|
+
res.end(JSON.stringify({ error: "internal" }));
|
|
25
|
+
} else try {
|
|
26
|
+
res.end();
|
|
27
|
+
} catch {}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
await new Promise((resolve, reject) => {
|
|
31
|
+
server.once("error", reject);
|
|
32
|
+
server.listen(port, () => {
|
|
33
|
+
server.removeListener("error", reject);
|
|
34
|
+
console.log(`[cron-host] listening on port ${port}`);
|
|
35
|
+
resolve();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
const shutdown = () => {
|
|
39
|
+
server.close(() => process.exit(0));
|
|
40
|
+
setTimeout(() => process.exit(0), 1e3).unref();
|
|
41
|
+
};
|
|
42
|
+
process.on("SIGTERM", shutdown);
|
|
43
|
+
process.on("SIGINT", shutdown);
|
|
44
|
+
}
|
|
45
|
+
main().catch((err) => {
|
|
46
|
+
console.error(err);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { };
|