• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Next.js 게시판 글작성기능 2 부분 서버로 데이터 넘기기 404에러

글작성기능 2 부분 서버로 데이터 넘기기 404에러

3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 글쓴이
  • #83009

    이로운
    참가자
    post 요청을 넣는데 404 페이지가 뜨는 이슈가 있습니다.
    일단 파일 위치는 사진 첨부 하겠습니다. app폴더 밖에 pages폴더가 있는거 같은데 무슨 문제일가요..
    콘솔 확인해보니 post 요청 한번 가고 get요청이 계속 갑니다
    - new.js -
    
    import { connectDB } from "@/util/database";
    export default async function handler(req, res) {
    console.log(req);
    if (req.method == "POST") {
    let db = (await connectDB).db("forum");
    let result = db.collection("post").insertOne(req.body);
    return res.redirect(302, "/cafe");
    }
    }
    - pages.js -
    
    export default function Write() {
    return (
    <div className="w-[828px] m-auto mt-[50px]">
    <h4 className="text-[25px] border-b-[1px] pb-[10px] text-[#081910]">
     카페추천
    </h4>
    <form action="/api/post/new" method="POST">
    <input
    className="block px-[6px] py-[10px] mt-[20px] w-[828px] border-[1px] rounded-lg"
    name="title"
    placeholder="제목을 작성해주세요"
    />
    <textarea
    className="block w-[828px] h-[400px] border-[1px] rounded-lg mt-[10px] px-[6px] pt-[10px] resize-none"
    name="content"
    placeholder="내용을 작성해주세요"
    />
    <button
    className="mt-[15px] flex sm:inline-flex justify-center items-center bg-teal-500 hover:bg-teal-600 active:bg-green-700 focus-visible:ring ring-green-300 text-white font-semibold text-center rounded-md outline-none transition duration-100 px-5 py-2"
    type="submit"
    >
     작성완료
    </button>
    </form>
    </div>
     );
    }
    #83013

    codingapple
    키 마스터
    db.collection("post").insertOne(req.body); 왼쪽에 await 씁시다
    #83016

    이로운
    참가자
    아....간단한 문제였느데 두시간 고민했네여....ㅋㅋㅋ감사합니다 쎔
3 글 보임 - 1 에서 3 까지 (총 3 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠