inflearn logo
강의

Course

Instructor

Learn by Following Along Node, React Series - Building a Shopping Mall Site [Complete Renewal]

5:40 404 에러 도와주세요 ㅠㅠ

614

esahn971149

4 asked

1

좋은 강의 항상 감사드립니다.

오타때문인가 싶어 강의도 돌려보고 올라와있는 질문들 다 읽어보았는데도 끝내 해결하지 못해 이렇게 질문드립니다.

일단 위 사진은 콘솔 창에서의 에러이구요...

소스코드 첨부하겠습니다.

FileUpload.js

import React from "react";
import Dropzone from "react-dropzone";
import { Icon } from "antd";
import axios from "axios";

function FileUpload() {
const dropHanler = (files) => {
let formData = new FormData();

const config = {
header: { "content-type": "multipart/form-data" },
};
formData.append("file", files[0]);
axios.post("/api/product/image", formData, config).then((response) => {
if (response.data.success) {
console.log(response.data);
} else {
alert("파일을 저장하는데 실패했습니다.");
}
});
};

return (
<div style={{ display: "flex", justifyContent: "space-between" }}>
<Dropzone onDrop={dropHanler}>
{({ getRootProps, getInputProps }) => (
<div
style={{
width: 300,
height: 240,
border: "1px solid lightgray",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
{...getRootProps()}
>
<input {...getInputProps()} />
<Icon type="plus" style={{ fontSize: "3rem " }} />
</div>
)}
</Dropzone>
</div>
);
}

export default FileUpload;

product.js

const express = require("express");
const router = express.Router();
const multer = require("multer");

//=================================
// Product
//=================================

var storage = multer.diskStorage({
// destination: 파일이 어디에 저장되는지 알려줌
destination: function (req, file, cb) {
cb(null, "uploads/");
},
filename: function (req, file, cb) {
cb(null, `${Date.now()}_${file.originalname}`);
},
});

var upload = multer({ storage: storage }).single("file");

router.post("/image", (req, res) => {
// 가져온 이미지를 저장해주면 된다
upload(req, res, (err) => {
if (err) {
return res.json({ success: false, err });
}
return res.json({
success: true,
filePath: res.req.file.path,
fileName: res.req.file.filename,
});
});
});

module.exports = router;

index.js(강의에서 손댄 부분만)

app.use("/api/users", require("./routes/users"));
app.post("/api/product", require("./routes/product"));

//use this to show the image you have in node js server to client (react js)
//https://stackoverflow.com/questions/48914987/send-image-path-from-node-js-express-server-to-react-client
app.use("/uploads", express.static("uploads"));

몽고db연결도 잘 되었고, 별 다른 에러가 뜨지 않아 터미널 로그는 따로 첨부하지 않았습니다.

혼자 해결해보려고 3시간 붙잡다 이렇게 질문드립니다... ㅠㅠ 꼭 답변 부탁드리겠습니다.. ㅠㅠ

nodejs react mongodb redux 웹앱

Answer 2

1

John Ahn

안녕하세요 

404에러면  요청의 경로에 맞는 핸들러가 없어서 나오는 에러인데 현재 
/api/product/image 잘 맞춰서 가고 있어서  혹시 proxy를 잘적용하셨나요 ?~!  

그래서   3000포트에서 자동으로 5000으로 라우팅이되야하는데     그 프록시 부분을 잘 설정하셨는지 궁금합니다 ~ 

0

esahn971149

해결했습니다. 결국엔 오타문제였네요 ㅎ ㅠㅠ 감사합니다!!!

강의 내용은 훌륭하나, 환경 설정 오류 때문에 진도를 나갈 수 없습니다. 20년 버전 강의.

0

61

1

강의자료는 어디서 볼 수있나요??

0

68

1

이 쇼핑몰 만들기 강의는 관리자페이지 만드는건 없나요

0

118

2

웹에서 실시간 코드반영이 안돼요

0

123

1

app.use질문

0

66

1

강사님께 어떻게 직접질문할수있어요??

0

76

1

const함수같은거 기초강의는 어디있나요

0

84

2

리덕스 참조챕터가 어딨어요? 미리듣고오라는데요

0

81

2

강의가완전 오래되서 다 틀리네 app.jsx도 tailwind css 다틀림 무책임함

0

69

1

개발자도구에 redux란이 없어요

0

90

1

npx tailwindcss init -p 에서 계속 에러나요

0

93

1

쇼핑몰기능중 찜하기 기능은 어떻게 구현하나요

0

141

2

강의하다 줌으로 설명가능한지좀 정확히 알려주세요. 이 선생님 정책이 어떻게 되는데요. 직접 연락할 메일이라도 알려주세요

0

44

1

도표 강의 자료 열람 불가능

0

110

1

tailwindcss를 vite에서 이용하는 방식이 바뀐것 같습니다.

0

1140

2

eslint 설정 후 오류가 납니다.

0

224

1

오버로드 오류

0

151

1

VSCode에서 save를 할 때, landingpage의 useEffect가 실행되는 문제에 대하여

0

170

1

dispatch(logoutUser()) 실행시 dispatch(authuser())도 함께 실행되는 문제

0

231

2

logout할 때, server로 요청을 보내서 authUser middleware를 통과하도록 하는 이유?

0

197

1

webkit-text-size-adjust 오류

0

316

1

does not provide an export named 'userReducer'

0

218

2

빌드 배포

0

140

1

삭제 예정 강의는 언제 삭제 되나요? 저것때문에 수강완료를 못하면 회사에서 비용을 청구한다고 합니다~

0

222

2