The serverless API for our final software engineering project.

getTopic.ts 777B

1234567891011121314151617181920212223242526
  1. // Next.js API route support: https://nextjs.org/docs/api-routes/introduction
  2. import type { NextApiRequest, NextApiResponse } from "next";
  3. import NextCors from "nextjs-cors";
  4. import { getDatabaseId, notion, renderClient } from "../../lib/notion";
  5. import { DatabaseType, Error, Topic } from "../../types";
  6. export default async function handler(
  7. req: NextApiRequest,
  8. res: NextApiResponse<any>
  9. ) {
  10. await NextCors(req, res, {
  11. methods: ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"],
  12. origin: "*",
  13. optionsSuccessStatus: 200,
  14. });
  15. const {
  16. query: { id },
  17. } = req;
  18. if (!id) {
  19. res.status(404).json({ status: "ID not supplied." });
  20. } else {
  21. const recordMap = await renderClient.getPage(id as string);
  22. res.status(200).json(recordMap);
  23. }
  24. }