@levo-so/next-middleware 0.1.71 → 0.1.78

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.
Files changed (2) hide show
  1. package/dist/index.js +11 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ function middleware(request, options = {}) {
7
7
  const { nextUrl } = request;
8
8
  const { pathname, search, hash } = nextUrl;
9
9
  const host = request.headers.get("host");
10
+ const workspace = request.headers.get("Levo-Workspace");
10
11
  // Clone the original request headers
11
12
  const modified_headers = new Headers(request.headers);
12
13
  if (host) {
@@ -17,7 +18,10 @@ function middleware(request, options = {}) {
17
18
  }
18
19
  if (host && pathname.startsWith("/.levo/public/api")) {
19
20
  const targetPath = pathname.replace(/^\/.levo\/public\/api/, "");
20
- const targetURL = `${apiUrl}${targetPath}${search}${hash}`;
21
+ const workspaceQuery = workspace && !search.includes("workspace=")
22
+ ? `${search ? "&" : "?"}workspace=${workspace}`
23
+ : "";
24
+ const targetURL = `${apiUrl}${targetPath}${search}${workspaceQuery}${hash}`;
21
25
  return NextResponse.rewrite(targetURL, {
22
26
  request: {
23
27
  headers: modified_headers,
@@ -26,7 +30,10 @@ function middleware(request, options = {}) {
26
30
  }
27
31
  if (host && pathname.startsWith("/.levo/insights/api")) {
28
32
  const targetPath = pathname.replace(/^\/.levo\/insights\/api/, "");
29
- const targetURL = `${insightsUrl}${targetPath}${search}${hash}`;
33
+ const workspaceQuery = workspace && !search.includes("workspace=")
34
+ ? `${search ? "&" : "?"}workspace=${workspace}`
35
+ : "";
36
+ const targetURL = `${insightsUrl}${targetPath}${search}${workspaceQuery}${hash}`;
30
37
  return NextResponse.rewrite(targetURL, {
31
38
  request: {
32
39
  headers: modified_headers,
@@ -45,7 +52,8 @@ function middleware(request, options = {}) {
45
52
  (!isHeadless && request.nextUrl.pathname.endsWith("llms.txt")) ||
46
53
  // check if it is a sitemap xml, can be `sitemap-static.xml`, `sitemap_index.xml` or other sitemap xml files
47
54
  (request.nextUrl.pathname.includes("sitemap") && request.nextUrl.pathname.endsWith(".xml"))) {
48
- const targetURL = `${apiUrl}/v1/studio/page/get-file-from-path?path=${pathname}`;
55
+ const workspaceQuery = workspace ? `&workspace=${workspace}` : "";
56
+ const targetURL = `${apiUrl}/v1/studio/page/get-file-from-path?path=${pathname}${workspaceQuery}`;
49
57
  return NextResponse.rewrite(targetURL, {
50
58
  request: {
51
59
  headers: modified_headers,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levo-so/next-middleware",
3
- "version": "0.1.71",
3
+ "version": "0.1.78",
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",