Skip to content

Instantly share code, notes, and snippets.

@ProfAvery
Last active October 8, 2024 17:42
Show Gist options
  • Save ProfAvery/7ac60e6aaefc0063be925862c2e78b5d to your computer and use it in GitHub Desktop.
Save ProfAvery/7ac60e6aaefc0063be925862c2e78b5d to your computer and use it in GitHub Desktop.
Updated Listing 7-9 - Summer 2024 AMSE Bootcamp
import type {NextApiRequest, NextApiResponse, NextApiHandler} from "next";
import {findByZip} from "./../../../../mongoose/weather/services";
import dbConnect from "./../../../../middleware/db-connect";
async function handler(
req: NextApiRequest,
res: NextApiResponse
): Promise<NextApiResponse<WeatherDetailType> | void> {
let data = await findByZip(req.query.zipcode as string);
return res.status(200).json(data);
}
const connectDB = (fn: NextApiHandler) =>
async (req: NextApiRequest, res: NextApiResponse) => {
await dbConnect();
return await fn(req, res);
};
export default connectDB(handler);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment