@levo-so/next-middleware 0.1.81 → 0.1.97

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.d.ts CHANGED
@@ -1,11 +1,17 @@
1
1
  import { type NextRequest, NextResponse } from "next/server";
2
2
  /**
3
- * @description This function can be marked `async` if using `await` inside
3
+ * Levo Next.js middleware rewrites API and SEO file requests to the appropriate backend.
4
+ *
5
+ * @param options.apiUrl - Base URL for the public API proxy. Defaults to `https://public-api.levo.so`.
6
+ * @param options.insightsUrl - Base URL for the insights API proxy. Defaults to `https://insights-api.levo.so`.
7
+ * @param options.fileExclusions - Paths to exclude from the SEO file proxy (robots.txt, llms.txt, sitemaps).
8
+ * Matched exactly against the request pathname.
9
+ * e.g. `["/robots.txt", "/llms.txt"]` prevents those files from being reverse-proxied.
4
10
  */
5
11
  declare function middleware(request: NextRequest, options?: {
6
12
  apiUrl?: string;
7
13
  insightsUrl?: string;
8
- isHeadless?: boolean;
14
+ fileExclusions?: string[];
9
15
  }): NextResponse<unknown> | undefined;
10
16
  declare const levoConfig: {
11
17
  matcher: string[];
package/dist/index.js CHANGED
@@ -1,9 +1,15 @@
1
1
  import { NextResponse } from "next/server";
2
2
  /**
3
- * @description This function can be marked `async` if using `await` inside
3
+ * Levo Next.js middleware rewrites API and SEO file requests to the appropriate backend.
4
+ *
5
+ * @param options.apiUrl - Base URL for the public API proxy. Defaults to `https://public-api.levo.so`.
6
+ * @param options.insightsUrl - Base URL for the insights API proxy. Defaults to `https://insights-api.levo.so`.
7
+ * @param options.fileExclusions - Paths to exclude from the SEO file proxy (robots.txt, llms.txt, sitemaps).
8
+ * Matched exactly against the request pathname.
9
+ * e.g. `["/robots.txt", "/llms.txt"]` prevents those files from being reverse-proxied.
4
10
  */
5
11
  function middleware(request, options = {}) {
6
- const { apiUrl = "https://public-api.levo.so", insightsUrl = "https://insights-api.levo.so", isHeadless = false, } = options;
12
+ const { apiUrl = "https://public-api.levo.so", insightsUrl = "https://insights-api.levo.so", fileExclusions = [], } = options;
7
13
  const { nextUrl } = request;
8
14
  const { pathname, search, hash } = nextUrl;
9
15
  const host = request.headers.get("host");
@@ -48,10 +54,14 @@ function middleware(request, options = {}) {
48
54
  * such as `text/plain` for `robots.txt` and `application/xml` for sitemaps
49
55
  *
50
56
  */
51
- if ((!isHeadless && request.nextUrl.pathname.endsWith("robots.txt")) ||
52
- (!isHeadless && request.nextUrl.pathname.endsWith("llms.txt")) ||
57
+ // Early return if the path is in the exclusions list
58
+ if (fileExclusions.includes(pathname))
59
+ return NextResponse.next();
60
+ const isFileProxy = pathname.endsWith("robots.txt") ||
61
+ pathname.endsWith("llms.txt") ||
53
62
  // check if it is a sitemap xml, can be `sitemap-static.xml`, `sitemap_index.xml` or other sitemap xml files
54
- (request.nextUrl.pathname.includes("sitemap") && request.nextUrl.pathname.endsWith(".xml"))) {
63
+ (pathname.includes("sitemap") && pathname.endsWith(".xml"));
64
+ if (isFileProxy) {
55
65
  const workspaceQuery = workspace ? `&workspace=${workspace}` : "";
56
66
  const targetURL = `${apiUrl}/v1/studio/page/get-file-from-path?path=${pathname}${workspaceQuery}`;
57
67
  return NextResponse.rewrite(targetURL, {
@@ -63,14 +73,13 @@ function middleware(request, options = {}) {
63
73
  }
64
74
  const levoConfig = {
65
75
  matcher: [
66
- /*
67
- * Match all request paths except for the ones starting with:
68
- * - api (API routes)
69
- * - _next/static (static files)
70
- * - _next/image (image optimization files)
71
- * - favicon.ico (favicon file)
72
- */
73
- "/((?!api|_next/static|_next/image|favicon.ico).*)",
76
+ // API proxy routes
77
+ "/.levo/public/api/:path*",
78
+ "/.levo/insights/api/:path*",
79
+ // SEO file proxy routes
80
+ "/robots.txt",
81
+ "/llms.txt",
82
+ "/(.*sitemap.*\\.xml)",
74
83
  ],
75
84
  };
76
85
  export default middleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levo-so/next-middleware",
3
- "version": "0.1.81",
3
+ "version": "0.1.97",
4
4
  "author": "Levo Engineering <devs@theinternetfolks.com>",
5
5
  "description": "Next middleware to add a proxy for levo integration in apps",
6
6
  "type": "module",
@@ -14,15 +14,15 @@
14
14
  "package.json"
15
15
  ],
16
16
  "peerDependencies": {
17
- "next": ">13.0.0 <=16"
17
+ "next": ">13.0.0 <=17"
18
18
  },
19
19
  "devDependencies": {
20
- "@types/react": "19.2.5",
20
+ "@types/react": "19.2.14",
21
21
  "@types/react-dom": "19.2.3",
22
22
  "babel-plugin-react-compiler": "19.1.0-rc.3",
23
- "next": "16.0.10",
24
- "react": "19.2.0",
25
- "react-dom": "19.2.0",
23
+ "next": "16.2.1",
24
+ "react": "19.2.4",
25
+ "react-dom": "19.2.4",
26
26
  "@levo/ts-config": "0.0.0"
27
27
  },
28
28
  "main": "./dist/index.js",