@olmocms/front 0.1.2 → 0.1.5
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/README.md +30 -44
- package/dist/auth/action.cjs +107 -0
- package/dist/auth/action.cjs.map +1 -0
- package/dist/auth/action.d.cts +6 -0
- package/dist/auth/action.d.ts +6 -0
- package/dist/auth/action.js +83 -0
- package/dist/auth/action.js.map +1 -0
- package/dist/chunk-RAI2AUWN.js +168 -0
- package/dist/chunk-RAI2AUWN.js.map +1 -0
- package/dist/cli/index.js +1 -1
- package/dist/components/index.cjs +88 -0
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.d.cts +17 -1
- package/dist/components/index.d.ts +17 -1
- package/dist/components/index.js +87 -0
- package/dist/components/index.js.map +1 -1
- package/dist/index.cjs +191 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -2
- package/dist/index.d.ts +18 -2
- package/dist/index.js +91 -2
- package/dist/index.js.map +1 -1
- package/dist/middleware/index.cjs +105 -2
- package/dist/middleware/index.cjs.map +1 -1
- package/dist/middleware/index.d.cts +3 -1
- package/dist/middleware/index.d.ts +3 -1
- package/dist/middleware/index.js +5 -3
- package/package.json +9 -3
- package/dist/chunk-GQITFXCV.js +0 -66
- package/dist/chunk-GQITFXCV.js.map +0 -1
package/dist/chunk-GQITFXCV.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
// src/middleware/chain.ts
|
|
2
|
-
import { NextResponse } from "next/server";
|
|
3
|
-
function chain(functions = [], index = 0) {
|
|
4
|
-
const current = functions[index];
|
|
5
|
-
if (current) {
|
|
6
|
-
const next = chain(functions, index + 1);
|
|
7
|
-
return current(next);
|
|
8
|
-
}
|
|
9
|
-
return () => NextResponse.next();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// src/middleware/headermiddleware.ts
|
|
13
|
-
import { NextRequest } from "next/server";
|
|
14
|
-
var headermiddleware = (next) => {
|
|
15
|
-
return async (request, _next) => {
|
|
16
|
-
const url = new URL(request.url);
|
|
17
|
-
const params = new URLSearchParams(url.search);
|
|
18
|
-
const headers = new Headers(request.headers);
|
|
19
|
-
headers.set("x-current-path", request.nextUrl.pathname);
|
|
20
|
-
headers.set("x-server", "true");
|
|
21
|
-
headers.set("olmo-preview", params.has("olmopreview").toString());
|
|
22
|
-
return next(new NextRequest(request.url, { headers }), _next);
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
// src/middleware/redirectmiddleware.ts
|
|
27
|
-
import { NextResponse as NextResponse2 } from "next/server";
|
|
28
|
-
var redirectmiddleware = (next) => {
|
|
29
|
-
return async (request, _next) => {
|
|
30
|
-
if (request.headers.has("rsc")) {
|
|
31
|
-
return next(request, _next);
|
|
32
|
-
}
|
|
33
|
-
if (!process.env.NEXT_PUBLIC_OLMO_TOKEN || !process.env.NEXT_PUBLIC_API_URL || !process.env.NEXT_PUBLIC_BASE_URL) {
|
|
34
|
-
return next(request, _next);
|
|
35
|
-
}
|
|
36
|
-
const pathNameWithTrailingSlash = request.nextUrl.pathname;
|
|
37
|
-
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/all/redirect`, {
|
|
38
|
-
method: "GET",
|
|
39
|
-
cache: "force-cache",
|
|
40
|
-
next: { tags: ["olmo", "redirect"] },
|
|
41
|
-
headers: { "front-token": process.env.NEXT_PUBLIC_OLMO_TOKEN }
|
|
42
|
-
});
|
|
43
|
-
const data = await response.json();
|
|
44
|
-
const redirects = data.map((e) => ({
|
|
45
|
-
source: e.source,
|
|
46
|
-
destination: e.destination,
|
|
47
|
-
permanent: e.permanent === "true"
|
|
48
|
-
}));
|
|
49
|
-
if (redirects.length > 0) {
|
|
50
|
-
const redirect = redirects.find((item) => item.source === pathNameWithTrailingSlash);
|
|
51
|
-
if (!redirect) {
|
|
52
|
-
return next(request, _next);
|
|
53
|
-
}
|
|
54
|
-
const newUrl = new URL(redirect.destination, process.env.NEXT_PUBLIC_BASE_URL).toString();
|
|
55
|
-
return NextResponse2.redirect(newUrl, { status: redirect.permanent ? 308 : 307 });
|
|
56
|
-
}
|
|
57
|
-
return next(request, _next);
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export {
|
|
62
|
-
chain,
|
|
63
|
-
headermiddleware,
|
|
64
|
-
redirectmiddleware
|
|
65
|
-
};
|
|
66
|
-
//# sourceMappingURL=chunk-GQITFXCV.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/middleware/chain.ts","../src/middleware/headermiddleware.ts","../src/middleware/redirectmiddleware.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport type { NextMiddleware } from 'next/server';\n\nexport type MiddlewareFactory = (middleware: NextMiddleware) => NextMiddleware;\n\nexport function chain(functions: MiddlewareFactory[] = [], index = 0): NextMiddleware {\n const current = functions[index];\n if (current) {\n const next = chain(functions, index + 1);\n return current(next);\n }\n return () => NextResponse.next();\n}\n","import { NextRequest } from 'next/server';\nimport type { NextFetchEvent } from 'next/server';\nimport type { MiddlewareFactory } from './chain.js';\n\nexport const headermiddleware: MiddlewareFactory = (next) => {\n return async (request: NextRequest, _next: NextFetchEvent) => {\n const url = new URL(request.url);\n const params = new URLSearchParams(url.search);\n\n const headers = new Headers(request.headers);\n headers.set('x-current-path', request.nextUrl.pathname);\n headers.set('x-server', 'true');\n headers.set('olmo-preview', params.has('olmopreview').toString());\n\n return next(new NextRequest(request.url, { headers }), _next);\n };\n};\n","import { NextResponse } from 'next/server';\nimport type { NextFetchEvent, NextRequest } from 'next/server';\nimport type { MiddlewareFactory } from './chain.js';\n\ntype NextFetchRequestInit = RequestInit & { next?: { tags?: string[]; revalidate?: number | false } };\n\nexport const redirectmiddleware: MiddlewareFactory = (next) => {\n return async (request: NextRequest, _next: NextFetchEvent) => {\n if (request.headers.has('rsc')) {\n return next(request, _next);\n }\n\n if (!process.env.NEXT_PUBLIC_OLMO_TOKEN || !process.env.NEXT_PUBLIC_API_URL || !process.env.NEXT_PUBLIC_BASE_URL) {\n return next(request, _next);\n }\n\n const pathNameWithTrailingSlash = request.nextUrl.pathname;\n\n const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/all/redirect`, {\n method: 'GET',\n cache: 'force-cache',\n next: { tags: ['olmo', 'redirect'] },\n headers: { 'front-token': process.env.NEXT_PUBLIC_OLMO_TOKEN },\n } as NextFetchRequestInit);\n\n const data = await response.json();\n\n const redirects = data.map((e: any) => ({\n source: e.source,\n destination: e.destination,\n permanent: e.permanent === 'true',\n }));\n\n if (redirects.length > 0) {\n const redirect = redirects.find((item: any) => item.source === pathNameWithTrailingSlash);\n\n if (!redirect) {\n return next(request, _next);\n }\n\n const newUrl = new URL(redirect.destination, process.env.NEXT_PUBLIC_BASE_URL).toString();\n return NextResponse.redirect(newUrl, { status: redirect.permanent ? 308 : 307 });\n }\n\n return next(request, _next);\n };\n};\n"],"mappings":";AAAA,SAAS,oBAAoB;AAKtB,SAAS,MAAM,YAAiC,CAAC,GAAG,QAAQ,GAAmB;AACpF,QAAM,UAAU,UAAU,KAAK;AAC/B,MAAI,SAAS;AACX,UAAM,OAAO,MAAM,WAAW,QAAQ,CAAC;AACvC,WAAO,QAAQ,IAAI;AAAA,EACrB;AACA,SAAO,MAAM,aAAa,KAAK;AACjC;;;ACZA,SAAS,mBAAmB;AAIrB,IAAM,mBAAsC,CAAC,SAAS;AAC3D,SAAO,OAAO,SAAsB,UAA0B;AAC5D,UAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,UAAM,SAAS,IAAI,gBAAgB,IAAI,MAAM;AAE7C,UAAM,UAAU,IAAI,QAAQ,QAAQ,OAAO;AAC3C,YAAQ,IAAI,kBAAkB,QAAQ,QAAQ,QAAQ;AACtD,YAAQ,IAAI,YAAY,MAAM;AAC9B,YAAQ,IAAI,gBAAgB,OAAO,IAAI,aAAa,EAAE,SAAS,CAAC;AAEhE,WAAO,KAAK,IAAI,YAAY,QAAQ,K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