@simpleview/cms-foundation 0.0.4 → 0.0.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.
|
@@ -10,36 +10,21 @@ async function getPageContent(req) {
|
|
|
10
10
|
cmsUrl.pathname = parsed_url.pathname + "content.json";
|
|
11
11
|
}
|
|
12
12
|
const headers = {
|
|
13
|
-
"Accept-Encoding": "gzip"
|
|
13
|
+
"Accept-Encoding": "gzip",
|
|
14
|
+
"X-Forwarded-For": req.headers.get("x-real-ip") || req.headers.get("x-forwarded-host") || "",
|
|
15
|
+
"User-Agent": req.headers.get("user-agent") || ""
|
|
14
16
|
};
|
|
15
|
-
if (req.headers.get("x-real-ip")) {
|
|
16
|
-
headers["X-Forwarded-For"] = req.headers.get("x-real-ip") || "";
|
|
17
|
-
}
|
|
18
|
-
if (req.headers.get("x-forwarded-host")) {
|
|
19
|
-
headers["X-Forwarded-For"] = req.headers.get("x-forwarded-host") || "";
|
|
20
|
-
}
|
|
21
|
-
if (req.headers.get("user-agent")) {
|
|
22
|
-
headers["User-Agent"] = req.headers.get("user-agent") || "";
|
|
23
|
-
}
|
|
24
17
|
try {
|
|
18
|
+
const url = cmsUrl.toString();
|
|
19
|
+
const { method } = req;
|
|
20
|
+
const body = JSON.stringify(data);
|
|
21
|
+
const fetchParams = { method, headers, body };
|
|
25
22
|
console.log("Making page content request:", {
|
|
26
|
-
url
|
|
27
|
-
|
|
28
|
-
headers,
|
|
29
|
-
body: data
|
|
30
|
-
});
|
|
31
|
-
const response = await fetch(cmsUrl.toString(), {
|
|
32
|
-
method: req.method,
|
|
33
|
-
headers,
|
|
34
|
-
body: JSON.stringify(data)
|
|
23
|
+
url,
|
|
24
|
+
...fetchParams
|
|
35
25
|
});
|
|
36
|
-
const result = await
|
|
37
|
-
|
|
38
|
-
...result,
|
|
39
|
-
headers: result.headers ?? [],
|
|
40
|
-
body: result.body
|
|
41
|
-
};
|
|
42
|
-
return resultWithData;
|
|
26
|
+
const result = await fetch(url, fetchParams).then((res) => res.json());
|
|
27
|
+
return result;
|
|
43
28
|
} catch (err) {
|
|
44
29
|
const status = err?.response?.status || 500;
|
|
45
30
|
const message = err?.response?.statusText || "Server Error";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/getPageContent.ts"],
|
|
4
|
-
"sourcesContent": ["import { IncomingMessage } from \"http\";\r\nimport type { CivProps, PageData } from \"../types\";\r\nimport { getCmsUrl } from \"./getCmsUrl\";\r\n\r\nexport type { PageData };\r\n\r\nexport async function getPageContent(\r\n\treq: Request\r\n): Promise<PageData<CivProps>> {\r\n\tlet data: undefined | IncomingMessage;\r\n\r\n\t// if (req.method === \"POST\") {\r\n\t// \t// if we have a POST req (most likely for Page Editor preview) then\r\n\t// \t// we'll pass the incoming req stream directly on to our outgoing\r\n\t// \t// req to the CMS. We don't do anything with the data here.\r\n\t// \tdata = req;\r\n\t// }\r\n\r\n\tconst parsed_url = new URL(req.url, \"http://placeholder.com\");\r\n\tconst cmsUrl = getCmsUrl(parsed_url.host);\r\n\r\n\tif (/\\.[^/]+$/.test(parsed_url.pathname)) {\r\n\t\t// If it's a file request, we append /content.json\r\n\t\tcmsUrl.pathname = parsed_url.pathname + \"/content.json\";\r\n\t} else {\r\n\t\t// If it's not a file request, we just append content.json since it already ends with a \"/\"\r\n\t\tcmsUrl.pathname = parsed_url.pathname + \"content.json\";\r\n\t}\r\n\r\n\tconst headers: Record<string, string> = {\r\n\t\t\"Accept-Encoding\": \"gzip\",\r\n\t
|
|
5
|
-
"mappings": "AAAA,SAAS,uBAAuB;AAEhC,SAAS,iBAAiB;AAI1B,eAAsB,eACrB,KAC8B;AAC9B,MAAI;AASJ,QAAM,aAAa,IAAI,IAAI,IAAI,KAAK,wBAAwB;AAC5D,QAAM,SAAS,UAAU,WAAW,IAAI;AAExC,MAAI,WAAW,KAAK,WAAW,QAAQ,GAAG;AAEzC,WAAO,WAAW,WAAW,WAAW;AAAA,EACzC,OAAO;AAEN,WAAO,WAAW,WAAW,WAAW;AAAA,EACzC;AAEA,QAAM,UAAkC;AAAA,IACvC,mBAAmB;AAAA,
|
|
4
|
+
"sourcesContent": ["import { IncomingMessage } from \"http\";\r\nimport type { CivProps, PageData } from \"../types\";\r\nimport { getCmsUrl } from \"./getCmsUrl\";\r\n\r\nexport type { PageData };\r\n\r\nexport async function getPageContent(\r\n\treq: Request\r\n): Promise<PageData<CivProps>> {\r\n\tlet data: undefined | IncomingMessage;\r\n\r\n\t// if (req.method === \"POST\") {\r\n\t// \t// if we have a POST req (most likely for Page Editor preview) then\r\n\t// \t// we'll pass the incoming req stream directly on to our outgoing\r\n\t// \t// req to the CMS. We don't do anything with the data here.\r\n\t// \tdata = req;\r\n\t// }\r\n\r\n\tconst parsed_url = new URL(req.url, \"http://placeholder.com\");\r\n\tconst cmsUrl = getCmsUrl(parsed_url.host);\r\n\r\n\tif (/\\.[^/]+$/.test(parsed_url.pathname)) {\r\n\t\t// If it's a file request, we append /content.json\r\n\t\tcmsUrl.pathname = parsed_url.pathname + \"/content.json\";\r\n\t} else {\r\n\t\t// If it's not a file request, we just append content.json since it already ends with a \"/\"\r\n\t\tcmsUrl.pathname = parsed_url.pathname + \"content.json\";\r\n\t}\r\n\r\n\tconst headers: Record<string, string> = {\r\n\t\t\"Accept-Encoding\": \"gzip\",\r\n\t\t\"X-Forwarded-For\":\r\n\t\t\treq.headers.get(\"x-real-ip\") ||\r\n\t\t\treq.headers.get(\"x-forwarded-host\") ||\r\n\t\t\t\"\",\r\n\t\t\"User-Agent\": req.headers.get(\"user-agent\") || \"\",\r\n\t};\r\n\r\n\ttry {\r\n\t\tconst url = cmsUrl.toString();\r\n\t\tconst { method } = req;\r\n\t\tconst body = JSON.stringify(data);\r\n\t\tconst fetchParams = { method, headers, body };\r\n\r\n\t\tconsole.log(\"Making page content request:\", {\r\n\t\t\turl,\r\n\t\t\t...fetchParams,\r\n\t\t});\r\n\r\n\t\tconst result = await fetch(url, fetchParams).then((res) => res.json());\r\n\r\n\t\treturn result;\r\n\t} catch (err: unknown) {\r\n\t\tconst status =\r\n\t\t\t(err as { response?: { status?: number } })?.response?.status ||\r\n\t\t\t500;\r\n\t\tconst message =\r\n\t\t\t(err as { response?: { statusText?: string } })?.response\r\n\t\t\t\t?.statusText || \"Server Error\";\r\n\t\tthrow new Error(`Status ${status}: ${message}`);\r\n\t}\r\n}\r\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,uBAAuB;AAEhC,SAAS,iBAAiB;AAI1B,eAAsB,eACrB,KAC8B;AAC9B,MAAI;AASJ,QAAM,aAAa,IAAI,IAAI,IAAI,KAAK,wBAAwB;AAC5D,QAAM,SAAS,UAAU,WAAW,IAAI;AAExC,MAAI,WAAW,KAAK,WAAW,QAAQ,GAAG;AAEzC,WAAO,WAAW,WAAW,WAAW;AAAA,EACzC,OAAO;AAEN,WAAO,WAAW,WAAW,WAAW;AAAA,EACzC;AAEA,QAAM,UAAkC;AAAA,IACvC,mBAAmB;AAAA,IACnB,mBACC,IAAI,QAAQ,IAAI,WAAW,KAC3B,IAAI,QAAQ,IAAI,kBAAkB,KAClC;AAAA,IACD,cAAc,IAAI,QAAQ,IAAI,YAAY,KAAK;AAAA,EAChD;AAEA,MAAI;AACH,UAAM,MAAM,OAAO,SAAS;AAC5B,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,OAAO,KAAK,UAAU,IAAI;AAChC,UAAM,cAAc,EAAE,QAAQ,SAAS,KAAK;AAE5C,YAAQ,IAAI,gCAAgC;AAAA,MAC3C;AAAA,MACA,GAAG;AAAA,IACJ,CAAC;AAED,UAAM,SAAS,MAAM,MAAM,KAAK,WAAW,EAAE,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC;AAErE,WAAO;AAAA,EACR,SAAS,KAAc;AACtB,UAAM,SACJ,KAA4C,UAAU,UACvD;AACD,UAAM,UACJ,KAAgD,UAC9C,cAAc;AAClB,UAAM,IAAI,MAAM,UAAU,MAAM,KAAK,OAAO,EAAE;AAAA,EAC/C;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simpleview/cms-foundation",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Provides helper types and components to assist when working with Granicus CMS Reactor.",
|
|
5
5
|
"packageManager": "yarn@4.6.0+sha224.acd0786f07ffc6c933940eb65fc1d627131ddf5455bddcc295dc90fd",
|
|
6
6
|
"scripts": {
|