2 min read

Next.js, Tailwind CSS and Contentlayer

Dummy content! Read Introduction, Installed Packages or Content

What will we buid

Mollit nisi cillum exercitation minim officia velit laborum non Lorem adipisicing dolore. Labore commodo consectetur commodo velit adipisicing irure dolore dolor reprehenderit aliquip. Reprehenderit cillum mollit eiusmod excepteur elit ipsum aute pariatur in. Cupidatat ex culpa velit culpa ad non labore exercitation irure introduction.

How can that be

This is an external link to google

Mollit nisi cillum exercitation minim officia velit laborum non Lorem adipisicing dolore. Labore commodo consectetur commodo velit adipisicing irure dolore dolor reprehenderit aliquip. Reprehenderit cillum mollit eiusmod excepteur elit ipsum aute pariatur in. Cupidatat ex culpa velit culpa ad non labore exercitation irure laborum.

Installation Process

const r = "";

Let's start coding

TODO: how to deal with title="hello world"

hello world
import type { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
import z from "zod";
import type { ZodSchema } from "zod";
import { getRequestCache } from "../redis/cache-request";
 
export function withCache<T extends ZodSchema>(
  schema: T, // query: string[] // list of all queries
  handler: NextApiHandler
) {
  return async function (req: NextApiRequest, res: NextApiResponse) {
    try {
      switch (req.method) {
        case "GET": {
          const result = schema.parse(req.query);
          const cache = await getRequestCache(result);
          if (cache) {
            return res
              .status(200) // or status 304 here?
              .setHeader("Upstash-Redis-Cache", 1) // distinguish response
              .json(cache);
          }
          return handler(req, res);
        }
        default: {
          return handler(req, res);
        }
      }
    } catch (error) {
      if (error instanceof z.ZodError) {
        return res.status(422).json(error.issues);
      }
      return res.status(500).end();
    }
  };
}

Final Thoughts

Mollit nisi cillum exercitation minim officia velit laborum non Lorem adipisicing dolore. Labore commodo consectetur commodo velit adipisicing irure dolore dolor reprehenderit aliquip. Reprehenderit cillum mollit eiusmod excepteur elit ipsum aute pariatur in. Cupidatat ex culpa velit culpa ad non labore exercitation irure laborum.

last edited: 4/1/2023