inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Một trại huấn luyện phát triển toàn diện thực sự dành cho những người không chuyên ngành

Triển khai API Tạo, Tra cứu Sản phẩm

postman에서 결과가 제대로 나오지 않습니다.

910

yami654

11 câu hỏi đã được viết

2

 send누르면  아래 사진 처럼 error가 발생합니다..

server.js 코드 작성한건데 어떤게 잘못 된건지 확인좀 해주세요ㅜㅡㅜ 올려주신 소스코드보고 확인해봤는데도 못찾겠어요..ㅜ

const express = require("express");
const cors = require("cors");
const app = express();
const models = require("./models");
const port = 8080;

app.use(express.json());
app.use(cors());

app.get("/products", (req, res) => {
  const query = req.query;
  console.log("QUERY : ", query);
  res.send({
    products: [
      {
        id: 1,
        name: "농구공",
        price: 100000,
        seller: "조던",
        imageUrl: "images/products/basketball1.jpeg",
      },
      {
        id: 2,
        name: "축구공",
        price: 50000,
        seller: "메시",
        imageUrl: "images/products/soccerball1.jpg",
      },
      {
        id: 3,
        name: "키보드",
        price: 10000,
        seller: "그랩",
        imageUrl: "images/products/keyboard1.jpg",
      },
    ],
  });
});

app.post("/products", (req, res) => {
  const body = req.body;
  const { name, description, price, seller } = body;
  models.Product.create({
    name,
    description,
    price,
    seller,
  })
    .then((result) => {
      console.log("상품 생성 결과 : ", result);
      res.send({
        result,
      });
    })
    .catch((error) => {
      console.error(error);
      res.send("상품 업로드에 문제가 발생했습니다.");
    });
});

app.get("/products/:id/events/:eventId", (req, res) => {
  const params = req.params;
  const { id, eventId } = params;
  res.send(`id는 ${id}와 ${eventId} 입니다`);
});

app.listen(port, () => {
  console.log("그랩의 쇼핑몰 서버가 돌아가고 있습니다.");
  models.sequelize
    .sync()
    .then(() => {
      console.log("DB 연결 성공!");
    })
    .catch((error) => {
      console.error(err);
      console.log("DB 연결 에러");
      process.exit();
    });
});

HTML/CSS tensorflow express react javascript 머신러닝 배워볼래요? react-native nodejs

Câu trả lời 3

1

yami654

또 질문 있습니다.!
상품정보를 덜 입력했을 때 '모든 필드를 입력해주세요.' 라는 문구가 떠야하는데 아래 사진처럼 코드로 뜹니다.

  

서버실행 했을 때 코드는 이렇게 뜨는데... 어느부분이 잘못된 걸 까요..ㅜㅜ

0

grab

해당 에러는 json 문법 오류와 관련이 있는 것 같아요! 생성쪽 api쪽 코드에 json 문법을 확인해보세요~!!

0

yami654

서버실행 할 때 로그에요!

0

grab

models/product.js 파일을 확인해보시곘어요? 2번째 라인에 "Product"로 잘 적혀져있을까요?

const product = sequelize.define("Product", {

0

yami654

해결됐어요!! 대문자로 바꾸니 됐어요!! 감사합니다.!

저 근데 어느부분보고 어디에 에러났는지 어떻게 알 수 있나요????

0

grab

cannot read property 'create' of undefined 에러는 create 메소드 혹은 자원에 접근할 때 undefined라는 자료형에서 접근하게 될 때 에러가납니다. 아래줄에 해당 에러가 나는 라인을 보면 server.js:43:18이 나옵니다.

즉 models.Product.create에 에러가 나는 것을 확인할 수 있고, Product가 undefined이기에 에러가 난다는 걸 확인할 수 있습니다. Product가 undefined인 것은 sequelize 모델을 설정할 때 생기는 에러라고 판단해서 의심을 해본 거구요 ㅎㅎ

0

grab

현재 models.Product.create 이 부분을 호출할 때 Product, 즉 상품쪽 모델이 제대로 생성되지 않은 것 같습니다!

서버에서 처음 프로그램을 실행할 때 로그는 어떻게 찍히나요?  

<div id="banner">배너 이미지</div> 관련 질문

0

91

1

[해결]그랩님 답변 주세요.

0

269

2

그랩님의 답변을 기다립니다/102강 전반적인 에러

0

239

2

[그랩님께]101강 안드로이드 에러들(Key prop)해결방법 궁금합니다.

0

199

2

[재질문][그랩님 답변 부탁드립니다]101강

0

264

2

[그랩님 답변 부탁드립니다]101강 Axios 에러와 502 Bad Gateway 질문

0

237

2

Ngrok 설치 후 forwarding Url 에러

0

216

2

[그랩님께,Ngrok 악성코드 인식 해결방법]질문 드립니다.

0

362

2

Ngrok 설치 후 forwarding Url로 연결 불가

0

207

1

그랩님,[꼭] 답변 부탁드립니다.

0

154

1

[꼭][[꼭] 그랩님, 답변 부탁드립니다], Failed to load resource: the server responded with a status of 404 (Not Found) 상품 상세 페이지 질문입니다.

0

207

1

6강/7강 수업

0

93

1

그랩님, 상품 상세 페이지 에러와 의문점 질문드립니다.

0

153

2

그랩님, 해결되지 않은 에러 메시지 [꼭] 답변 부탁 드립니다.

0

195

2

[재 질문]Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

158

1

Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

246

2

일반적인 css 꾸미기에서 width와 height의 값?

0

152

2

Windows에서의 업로드 후 홈화면 상품이미지 오류 해결방법

0

257

1

그랩마켓 웹화면 구현하기 -2 질문입니다.

0

168

1

react에 반영이 되지 않습니다.

0

305

1

터미널 npm install -g create-react-app 작성 후 오류

0

480

1

create-react-app my app 실행 시 에러

0

415

2

포스트맨 질문

0

141

1

<꼭 답변 부탁 드립니다>그랩선생님, [컴포넌트 사용하기] 강의에서 질문 있습니다.

0

325

2