{"size": 927, "ext": "js", "max_stars_repo_path": "pages/api/board/interest.js", "max_stars_repo_name": "domfam012/MyXD", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pages/api/board/interest.js", "max_issues_repo_name": "domfam012/MyXD", "max_issues_repo_issues_event_min_datetime": "2021-03-10T06:34:35.000Z", "max_issues_repo_issues_event_max_datetime": "2021-08-13T02:34:36.000Z", "max_forks_repo_path": "pages/api/board/interest.js", "max_forks_repo_name": "domfam012/MyXD", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 23.175, "max_line_length": 74, "alphanum_fraction": 0.5674217907}
/**
 *  인기 글 목록 3개 조회
 */

import { loadDB } from "../../../public/js/db";

export default async (req, res) => {
  res.setHeader("Access-Control-Allow-Origin", "*");
  res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
  res.setHeader("Access-Control-Allow-Headers", "content-type");
  res.setHeader("Content-Type", "application/json");

  // console.log(`req.method : ${req.method}`);

  const db = await loadDB();
  const collection = await db.collection("Posts");

  if (req.method === "GET") {
    const ref = await collection
      .orderBy("viewCount", "desc")
      .limit(3)
      .get();
    const data = [];
    ref.forEach(doc => {
      data.push({ pid: doc.id, ...doc.data() });
    });

    const resData = JSON.stringify({
      status: 200,
      msg: "success",
      data: data
    });

    res.status(200).send(resData);
  } else {
    //
    res.json({ status: 405, msg: "" });
  }
};
