eddev 0.2.14 → 0.2.17

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "0.2.14",
3
+ "version": "0.2.17",
4
4
  "main": "./index.js",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -1,3 +1,4 @@
1
+ import type { NextApiRequest, NextApiResponse } from "next"
1
2
  import { fetchWP } from "../../../_utils/fetch-wp"
2
3
 
3
4
  const validProxyPaths = {
@@ -15,7 +16,7 @@ const validProxyPaths = {
15
16
  },
16
17
  }
17
18
 
18
- export default async function (req: any, res: any) {
19
+ export default async function (req: NextApiRequest, res: NextApiResponse) {
19
20
  // Ensure that the request is for a proxy path
20
21
  const proxyPath = validProxyPaths[req.query.method[0] as keyof typeof validProxyPaths]!
21
22
 
@@ -25,7 +26,7 @@ export default async function (req: any, res: any) {
25
26
  })
26
27
  }
27
28
 
28
- const finalPath = proxyPath.path.replace("*", req.query.method.slice(1).join("/"))
29
+ const finalPath = proxyPath.path.replace("*", (req.query.method as string[]).slice(1).join("/"))
29
30
 
30
31
  const response = await fetchWP(
31
32
  process.env.SITE_URL + finalPath,
@@ -37,8 +38,13 @@ export default async function (req: any, res: any) {
37
38
  },
38
39
  async (response) => ({
39
40
  payload: await response.json(),
41
+ cacheFor: parseInt(response.headers.get("x-ed-cache-duration") || "") || 0,
40
42
  })
41
43
  )
42
44
 
45
+ if (response.cacheFor) {
46
+ res.setHeader("Cache-Control", `max-age=${response.cacheFor}, stale-while-revalidate=20`)
47
+ }
48
+
43
49
  res.status(200).json(response.payload)
44
50
  }