@farm.js/plugin 0.1.0-beta.94 → 0.1.0-beta.95

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAKlD,MAAM,WAAW,cAAc;IAC7B,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,MAAM,CAogBpE;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,MAAM,CAAC;AAMlD,MAAM,WAAW,cAAc;IAC7B,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,MAAM,CA8gBpE;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/dist/api/index.js CHANGED
@@ -22,6 +22,7 @@
22
22
  * ```
23
23
  */
24
24
  import { _withAfterNodeMiddleware } from "@farm.js/core/after";
25
+ import { _runWithAPIRequestRuntime } from "@farm.js/core/internal/production-runtime";
25
26
  import { invokeAPIRouteEndpoint } from "@farm.js/core/api/runtime";
26
27
  import { sendWebResponse } from "@farm.js/core/server";
27
28
  /**
@@ -281,7 +282,7 @@ export default function farmApi(options = {}) {
281
282
  };
282
283
  // Add middleware to handle API requests
283
284
  return () => {
284
- server.middlewares.use(_withAfterNodeMiddleware(async (req, res, next) => {
285
+ const apiMiddleware = _withAfterNodeMiddleware(async (req, res, next) => {
285
286
  const url = req.url || "/";
286
287
  const pathname = url.split("?")[0];
287
288
  const method = req.method || "GET";
@@ -349,7 +350,13 @@ export default function farmApi(options = {}) {
349
350
  res.setHeader("Content-Type", "application/json");
350
351
  res.end(JSON.stringify({ error: "Internal server error" }));
351
352
  }
352
- }));
353
+ });
354
+ server.middlewares.use((req, res, next) => _runWithAPIRequestRuntime({
355
+ basePath: "/api",
356
+ dispatch: async (request) => apiRouterHandler
357
+ ? apiRouterHandler(request)
358
+ : Response.json({ error: "Not Found" }, { status: 404 }),
359
+ }, () => apiMiddleware(req, res, next)));
353
360
  };
354
361
  },
355
362
  async handleHotUpdate({ file, server, modules }) {
package/dist/index.d.ts CHANGED
@@ -39,5 +39,5 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export declare const version = "0.1.0-beta.94";
42
+ export declare const version = "0.1.0-beta.95";
43
43
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@
39
39
  * })
40
40
  * ```
41
41
  */
42
- export const version = "0.1.0-beta.94";
42
+ export const version = "0.1.0-beta.95";
43
43
  // Note: Import plugins from their respective subpaths:
44
44
  // - @farm.js/plugin/rsc
45
45
  // - @farm.js/plugin/middleware
@@ -1 +1 @@
1
- {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CA06B1D"}
1
+ {"version":3,"file":"rsc.d.ts","sourceRoot":"","sources":["../../../src/rsc/entries/rsc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CA86B1D"}
@@ -58,7 +58,7 @@ import {
58
58
  matchAPIRouteAtBasePath,
59
59
  } from '@farm.js/core/api/runtime';
60
60
  import { _runWithAfterRequest } from '@farm.js/core/after';
61
- import { _runWithCurrentRequest, searchParamsToObject } from '@farm.js/core/internal/production-runtime';
61
+ import { _runWithAPIRequestRuntime, _runWithCurrentRequest, searchParamsToObject } from '@farm.js/core/internal/production-runtime';
62
62
  import { getFarmRedirectError, isFarmNotFoundError } from '@farm.js/core/internal/production-runtime';
63
63
  import {
64
64
  parseRoutePath,
@@ -910,9 +910,13 @@ async function handleFarmRequest(request) {
910
910
  }
911
911
 
912
912
  async function handler(request, context) {
913
- return _runWithCurrentRequest(request, () =>
913
+ return _runWithAPIRequestRuntime({
914
+ basePath: farmApiBasePath,
915
+ dispatch: async (localRequest) =>
916
+ (await handleAPIRequest(localRequest)) ?? Response.json({ error: 'Not Found' }, { status: 404 }),
917
+ }, () => _runWithCurrentRequest(request, () =>
914
918
  _runWithAfterRequest(request, () => handleFarmRequest(request), context)
915
- );
919
+ ));
916
920
  }
917
921
 
918
922
  export default { fetch: handler };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farm.js/plugin",
3
- "version": "0.1.0-beta.94",
3
+ "version": "0.1.0-beta.95",
4
4
  "description": "Official plugins for Farm.js framework",
5
5
  "license": "MIT",
6
6
  "author": "Farm.js Team",
@@ -61,7 +61,7 @@
61
61
  "nitro": "3.0.1-alpha.0",
62
62
  "picocolors": "^1.0.0",
63
63
  "rsc-html-stream": "^0.0.4",
64
- "@farm.js/core": "0.1.0-beta.94"
64
+ "@farm.js/core": "0.1.0-beta.95"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/node": "^20.19.21",
@@ -82,7 +82,7 @@
82
82
  "react-dom": "19.2.8",
83
83
  "react-server-dom-webpack": "19.2.8",
84
84
  "vite": ">=6.0.0",
85
- "@farm.js/core": "0.1.0-beta.94"
85
+ "@farm.js/core": "0.1.0-beta.95"
86
86
  },
87
87
  "peerDependenciesMeta": {
88
88
  "@vitejs/plugin-rsc": {