@rpcbase/api 0.97.0 → 0.98.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/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -21471,13 +21471,18 @@ const initApi = async ({
|
|
|
21471
21471
|
routes,
|
|
21472
21472
|
cors: corsOptions
|
|
21473
21473
|
}) => {
|
|
21474
|
-
await initApiClient({
|
|
21474
|
+
await initApiClient({
|
|
21475
|
+
app
|
|
21476
|
+
});
|
|
21475
21477
|
const registerHandler = (method, path, handler) => {
|
|
21476
21478
|
assert(path.startsWith("/api"), "API routes must start with /api");
|
|
21477
21479
|
app[method](path, async (req, res, next) => {
|
|
21478
21480
|
const payload = req.body || {};
|
|
21479
21481
|
try {
|
|
21480
|
-
const result = await handler(payload, {
|
|
21482
|
+
const result = await handler(payload, {
|
|
21483
|
+
req,
|
|
21484
|
+
res
|
|
21485
|
+
});
|
|
21481
21486
|
if (res.headersSent) return;
|
|
21482
21487
|
if (res.statusCode === 204) return res.end();
|
|
21483
21488
|
res.json(result);
|
|
@@ -21504,7 +21509,9 @@ const initApi = async ({
|
|
|
21504
21509
|
}
|
|
21505
21510
|
};
|
|
21506
21511
|
app.use("/api", cors(corsOptions));
|
|
21507
|
-
app.use("/api", expressExports.json({
|
|
21512
|
+
app.use("/api", expressExports.json({
|
|
21513
|
+
limit: "8mb"
|
|
21514
|
+
}));
|
|
21508
21515
|
app.use("/api", function __FIRST_API_MIDDLEWARE__(_req, _res, next) {
|
|
21509
21516
|
next();
|
|
21510
21517
|
});
|
|
@@ -21520,7 +21527,9 @@ const initApi = async ({
|
|
|
21520
21527
|
console.log(`loaded ${loadedCount}/${totalRoutes} api routes`);
|
|
21521
21528
|
}
|
|
21522
21529
|
return routeModule;
|
|
21523
|
-
}, {
|
|
21530
|
+
}, {
|
|
21531
|
+
concurrency: 32
|
|
21532
|
+
});
|
|
21524
21533
|
for (const [routePath] of routeEntries) {
|
|
21525
21534
|
const routeModule = loadedModules.get(routePath);
|
|
21526
21535
|
const routeRegistrar = routeModule?.default;
|
|
@@ -21536,7 +21545,9 @@ const initApi = async ({
|
|
|
21536
21545
|
}
|
|
21537
21546
|
console.log("Done loading routes");
|
|
21538
21547
|
app.use("/api", (req, res) => {
|
|
21539
|
-
res.status(404).json({
|
|
21548
|
+
res.status(404).json({
|
|
21549
|
+
error: `Not Found: ${req.method}:${req.originalUrl}`
|
|
21550
|
+
});
|
|
21540
21551
|
});
|
|
21541
21552
|
app.use("/api", (err, _req, res, next) => {
|
|
21542
21553
|
if (res.headersSent) return next(err);
|
|
@@ -21544,7 +21555,9 @@ const initApi = async ({
|
|
|
21544
21555
|
const code = typeof errLike?.code === "string" ? errLike.code : null;
|
|
21545
21556
|
const statusCode = typeof errLike?.statusCode === "number" ? errLike.statusCode : typeof errLike?.status === "number" ? errLike.status : null;
|
|
21546
21557
|
if (code === "invalid_pagination") {
|
|
21547
|
-
res.status(statusCode ?? 400).json({
|
|
21558
|
+
res.status(statusCode ?? 400).json({
|
|
21559
|
+
error: code
|
|
21560
|
+
});
|
|
21548
21561
|
return;
|
|
21549
21562
|
}
|
|
21550
21563
|
next(err);
|