@levo-so/next-middleware 0.1.82 → 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 +8 -2
- package/dist/index.js +22 -13
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { type NextRequest, NextResponse } from "next/server";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
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",
|
|
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
|
|
52
|
-
|
|
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
|
-
(
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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.
|
|
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 <=
|
|
17
|
+
"next": ">13.0.0 <=17"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@types/react": "19.2.
|
|
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.
|
|
24
|
-
"react": "19.2.
|
|
25
|
-
"react-dom": "19.2.
|
|
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",
|