@levo-so/next-middleware 0.1.102 → 0.3.7

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 +23 -0
  2. package/package.json +19 -18
package/dist/index.js CHANGED
@@ -22,12 +22,35 @@ function middleware(request, options = {}) {
22
22
  // new URL(request.url).protocol = "http:"
23
23
  modified_headers.set("origin", `${new URL(request.url).protocol}//${host}`);
24
24
  }
25
+ // Dev-only: tell the backend the proxied request is https so its
26
+ // ingress-nginx `force-ssl-redirect` doesn't 308 us to a port-stripped
27
+ // URL (`next dev` serves over plain http). Gated off in production, where
28
+ // genuine http must still redirect and these paths bypass this code.
29
+ if (process.env.NODE_ENV !== "production") {
30
+ modified_headers.set("x-forwarded-proto", "https");
31
+ }
25
32
  if (host && pathname.startsWith("/.levo/public/api")) {
26
33
  const targetPath = pathname.replace(/^\/.levo\/public\/api/, "");
27
34
  const workspaceQuery = workspace && !search.includes("workspace=")
28
35
  ? `${search ? "&" : "?"}workspace=${workspace}`
29
36
  : "";
30
37
  const targetURL = `${apiUrl}${targetPath}${search}${workspaceQuery}${hash}`;
38
+ // SSE endpoints must opt out of Next.js's gzip layer when running under
39
+ // `next dev`. Dev mode buffers ~16KB before flushing, which collapses
40
+ // per-token text-deltas into one frame and breaks the wire-level streaming
41
+ // the BE provides. We can't set a response header from middleware on
42
+ // absolute-URL rewrites (Next discards them), so we override the incoming
43
+ // `Accept-Encoding` to `identity` — Next's compression middleware reads
44
+ // request accept-encoding before deciding to gzip, and `identity` skips it.
45
+ //
46
+ // Gated to `NODE_ENV !== "production"` because production runs behind a
47
+ // CDN / nginx layer that handles SSE pass-through correctly; we don't want
48
+ // to force-disable encoding negotiation for real traffic. `NODE_ENV` is
49
+ // inlined at build time, so the entire block is dead-code-eliminated from
50
+ // the production bundle.
51
+ if (process.env.NODE_ENV !== "production" && targetPath.endsWith("/stream")) {
52
+ modified_headers.set("accept-encoding", "identity");
53
+ }
31
54
  return NextResponse.rewrite(targetURL, {
32
55
  request: {
33
56
  headers: modified_headers,
package/package.json CHANGED
@@ -1,37 +1,38 @@
1
1
  {
2
2
  "name": "@levo-so/next-middleware",
3
- "version": "0.1.102",
4
- "author": "Levo Engineering <devs@theinternetfolks.com>",
5
3
  "description": "Next middleware to add a proxy for levo integration in apps",
6
- "type": "module",
7
- "sideEffects": false,
8
- "publishConfig": {
9
- "access": "public"
10
- },
11
- "files": [
12
- "dist/**",
13
- "!dist/**/*.d.ts.map",
14
- "package.json"
15
- ],
16
- "peerDependencies": {
17
- "next": ">13.0.0 <=17"
18
- },
4
+ "version": "0.3.7",
5
+ "author": "Levo Engineering <devs@theinternetfolks.com>",
19
6
  "devDependencies": {
20
7
  "@types/react": "19.2.14",
21
8
  "@types/react-dom": "19.2.3",
22
9
  "babel-plugin-react-compiler": "19.1.0-rc.3",
23
- "next": "16.2.3",
10
+ "next": "16.2.6",
24
11
  "react": "19.2.4",
25
12
  "react-dom": "19.2.4",
26
13
  "@levo/ts-config": "0.0.0"
27
14
  },
15
+ "files": [
16
+ "dist/**",
17
+ "!dist/**/*.d.ts.map",
18
+ "!dist/**/*.js.map",
19
+ "package.json"
20
+ ],
28
21
  "main": "./dist/index.js",
29
22
  "module": "./dist/index.js",
23
+ "peerDependencies": {
24
+ "next": ">13.0.0 <=17"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "sideEffects": false,
30
+ "type": "module",
30
31
  "types": "./dist/index.d.ts",
31
32
  "scripts": {
32
- "clean": "rimraf dist node_modules .turbo",
33
- "check-types": "tsc --noEmit",
34
33
  "build": "tsc",
34
+ "check-types": "tsc --noEmit",
35
+ "clean": "npx rimraf dist node_modules .turbo",
35
36
  "dev": "tsc --watch"
36
37
  }
37
38
  }