해결된 질문
작성
·
2K
0
강의 내용을 토대로 웹을 구축하고 있는데요. 이미지 쪽에서 많은 걸림돌이 있어서요.
그냥 multer로 했을 때에는 괜찮았는데요.
s3로 변경하고 아래와 같은 에러가 발생합니다ㅜㅜ
Error: connect EHOSTUNREACH 169.254.169.254:80 - Local (192.168.1.104:49327)
at internalConnect (net.js:923:16)
at defaultTriggerAsyncIdScope (internal/async_hooks.js:351:12)
at net.js:1011:9
at processTicksAndRejections (internal/process/task_queues.js:79:11)
답변 7
0
0
감사합니다!!! 저 에러는 해결했는데요ㅜㅜㅜㅜㅜ
또 에러가 나네요 ㅠㅠ MAP을 못찾는다는데요 ㅜㅜㅜㅜㅜ
TypeError: Cannot read property 'map' of undefined
at /Users/sunjaekim/Documents/PROJECTS/asumtable-backend/routes/users.js:125:26
at Layer.handle [as handle_request] (/Users/sunjaekim/Documents/PROJECTS/asumtable-backend/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/sunjaekim/Documents/PROJECTS/asumtable-backend/node_modules/express/lib/router/route.js:137:13)
at Immediate._onImmediate (/Users/sunjaekim/Documents/PROJECTS/asumtable-backend/node_modules/multer/lib/make-middleware.js:53:37)
at processImmediate (internal/timers.js:458:21)
TypeError: Cannot read property 'map' of undefined
at /Users/sunjaekim/Documents/PROJECTS/asumtable-backend/routes/users.js:125:26
at Layer.handle [as handle_request] (/Users/sunjaekim/Documents/PROJECTS/asumtable-backend/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/sunjaekim/Documents/PROJECTS/asumtable-backend/node_modules/express/lib/router/route.js:137:13)
at Immediate._onImmediate (/Users/sunjaekim/Documents/PROJECTS/asumtable-backend/node_modules/multer/lib/make-middleware.js:53:37)
at processImmediate (internal/timers.js:458:21)
POST /api/user/image 500 27.541 ms - 779
0
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
이 두 값이 잘못 설정된 것 같습니다.
console.log로 두 값을 찍어보세요.
0
에러메세지 전문 입니다. :)
Error: connect EHOSTDOWN 169.254.169.254:80 - Local (192.168.1.104:62481)
at internalConnect (net.js:923:16)
at defaultTriggerAsyncIdScope (internal/async_hooks.js:351:12)
at net.js:1011:9
at processTicksAndRejections (internal/process/task_queues.js:79:11)
POST /api/test/images 500 5613.658 ms - 452
APP.js
const express = require("express");
const cors = require("cors");
const session = require("express-session");
const cookieParser = require("cookie-parser");
const passport = require("passport");
const dotenv = require("dotenv");
const logger = require("morgan");
const path = require("path");
const connectRedis = require("connect-redis");
const RedisStore = connectRedis(session);
var indexRouter = require("./routes/index");
var authRouter = require("./routes/auths");
var userRouter = require("./routes/users");
var hostRouter = require("./routes/hosts");
var adminRouter = require("./routes/users");
var tourRouter = require("./routes/tours");
var favoriteRouter = require("./routes/favorites");
var orderRouter = require("./routes/orders");
var imageRouter = require("./routes/images");
var testRouter = require("./routes/imageTest");
const db = require("./models/index");
const passportConfig = require("./passport");
dotenv.config();
const app = express();
db.sequelize
.sync({ force: false })
.then(() => {
console.log("ASUM_DB Sequelize Sync Success");
})
.catch(console.error);
passportConfig();
const sessionOption = {
resave: false,
saveUninitialized: false,
secret: process.env.COOKIE_SECRET,
proxy: true,
name: "sessionID",
cookie: {
httpOnly: true,
secure: false,
},
store: new RedisStore({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
pass: process.env.REDIS_PASSWORD,
logErrors: true,
}),
};
app.use("/", express.static(path.join(__dirname, "/uploads")));
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
app.use(cookieParser(process.env.COOKIE_SECRET));
app.use(session(sessionOption));
app.use(logger("dev"));
app.use(cors({ origin: true, credentials: true }));
app.use(passport.initialize());
app.use(passport.session());
app.use("/api", indexRouter);
app.use("/api/auth", authRouter);
app.use("/api/user", userRouter);
app.use("/api/host", hostRouter);
app.use("/api/admin", adminRouter);
app.use("/api/tours", tourRouter);
app.use("/api/favorites", favoriteRouter);
app.use("/api/orders", orderRouter);
app.use("/api/images", imageRouter);
app.use("/api/test", testRouter);
module.exports = app;
ROUTER
const express = require("express");
const multer = require("multer");
const path = require("path");
const multerS3 = require("multer-s3");
const AWS = require("aws-sdk");
const router = express.Router();
const dotenv = require("dotenv");
const { Tour, Image, Host, User } = require("../models");
const { isLoggedIn } = require("./middlewares");
// AWS-S3 설정
AWS.config.update({
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
region: "ap-northeast-2",
});
//MULTER-S3 설정
const upload = multer({
storage: multerS3({
s3: new AWS.S3(),
bucket: "asumtable-v1.0-s3",
key(req, file, cb) {
cb(null, `original/${Date.now()}_${path.basename(file.originalname)}`);
},
}),
limits: { fileSize: 10 * 1024 * 1024 },
});
//이미지 저장 위치 맴핑
router.post(
"/images",
// isLoggedIn,
upload.array("image"),
(req, res, next) => {
// POST /post/images
console.log(req.files);
res.json(
req.files.map((v) => v.location.replace(/\/original\//, "/thumb/"))
);
}
);
module.exports = router;
0
세팅이 안 되었다는게 이제는 세팅을 하셨다는 뜻인가요? 세팅하신 후에는 어떤가요?
그리고 위에 에러메시지도 중요한 부분이 짤렸습니다. 전체 메시지를 올려주세요.
0
넵!! AWS 관련 키들은 .env에 넣어 두었구요. 버킷도 퍼블릭으로 설정해두었습니다!!
(서버에서는 aws.configure로 세팅) <---- 이 부분이 세팅이 안된거 같아요 ㅜㅜ
0
multer-s3 사용하시는 상황이신거죠?
그리고 AWS 관련 키들은 엑셀 파일에서 꺼내신 후 모두 다 .env에 넣어두셨나요?(서버에서는 aws.config로 세팅)
그리고 연결하시고자 하는 S3 버킷이 퍼블릭으로 설정되어 있나요?
https://github.com/ZeroCho/react-nodebird/blob/master/https/back/routes/post.js