@levo-so/next-middleware 0.1.14 → 0.1.20
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 +1 -0
- package/dist/index.js +4 -3
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type NextRequest, NextResponse } from "next/server";
|
|
|
5
5
|
declare function middleware(request: NextRequest, options?: {
|
|
6
6
|
apiUrl?: string;
|
|
7
7
|
insightsUrl?: string;
|
|
8
|
+
isHeadless?: boolean;
|
|
8
9
|
}): NextResponse<unknown> | undefined;
|
|
9
10
|
declare const levoConfig: {
|
|
10
11
|
matcher: string[];
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { NextResponse } from "next/server";
|
|
|
3
3
|
* @description This function can be marked `async` if using `await` inside
|
|
4
4
|
*/
|
|
5
5
|
function middleware(request, options = {}) {
|
|
6
|
-
const { apiUrl = "https://public-api.levo.so", insightsUrl = "https://insights-api.levo.so", } = options;
|
|
6
|
+
const { apiUrl = "https://public-api.levo.so", insightsUrl = "https://insights-api.levo.so", isHeadless = false, } = options;
|
|
7
7
|
const { nextUrl } = request;
|
|
8
8
|
const { pathname, search, hash } = nextUrl;
|
|
9
9
|
const host = request.headers.get("host");
|
|
@@ -26,7 +26,7 @@ function middleware(request, options = {}) {
|
|
|
26
26
|
}
|
|
27
27
|
if (host && pathname.startsWith("/.levo/insights/api")) {
|
|
28
28
|
const targetPath = pathname.replace(/^\/.levo\/insights\/api/, "");
|
|
29
|
-
const targetURL = `${insightsUrl}${targetPath}`;
|
|
29
|
+
const targetURL = `${insightsUrl}${targetPath}${search}${hash}`;
|
|
30
30
|
return NextResponse.rewrite(targetURL, {
|
|
31
31
|
request: {
|
|
32
32
|
headers: modified_headers,
|
|
@@ -39,8 +39,9 @@ function middleware(request, options = {}) {
|
|
|
39
39
|
* Since NextJS can serve file types other than `text/html`, we have to specifically reverse proxy
|
|
40
40
|
* file-based path to the backend server directly, which serves the file, if found in appropriate filetypes
|
|
41
41
|
* such as `text/plain` for `robots.txt` and `application/xml` for sitemaps
|
|
42
|
+
*
|
|
42
43
|
*/
|
|
43
|
-
if (request.nextUrl.pathname.endsWith("robots.txt") ||
|
|
44
|
+
if ((!isHeadless && request.nextUrl.pathname.endsWith("robots.txt")) ||
|
|
44
45
|
// check if it is a sitemap xml, can be `sitemap-static.xml`, `sitemap_index.xml` or other sitemap xml files
|
|
45
46
|
(request.nextUrl.pathname.includes("sitemap") &&
|
|
46
47
|
request.nextUrl.pathname.endsWith(".xml"))) {
|
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.20",
|
|
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",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"next": ">=13"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
+
"@levo/eslint-config": "0.0.0",
|
|
20
21
|
"@levo/ts-config": "0.0.0"
|
|
21
22
|
},
|
|
22
23
|
"main": "./dist/index.js",
|
|
@@ -25,8 +26,7 @@
|
|
|
25
26
|
"scripts": {
|
|
26
27
|
"clean": "rimraf dist node_modules .turbo",
|
|
27
28
|
"check-types": "tsc --noEmit",
|
|
28
|
-
"
|
|
29
|
-
"format-and-lint:fix": "biome check . --write --diagnostic-level=error",
|
|
29
|
+
"lint": "eslint",
|
|
30
30
|
"build": "tsc",
|
|
31
31
|
"dev": "tsc --watch"
|
|
32
32
|
}
|