제출 후 해설강의를 듣고 보완한 부분과 오후동안 추가로 구현한 부분을 적어보겠음
status: {
type: String, // status 필드 추가
enum: ["FOR_SALE", "SOLD_OUT"],
default: "FOR_SALE", // 기본 값은 "FOR_SALE"
}
// 피드백 적용: for문 활용
for (const [key, value] of Object.entries(validation)) {
product[key] = value;
}
// 기존
Object.assign(product, validation);
import express from "express";
import connect from "./schemas/index.js";
import spartRouter from "./routes/spart.router.js";
import errorHandler from "./middlewares/error-handler.js";
import Spart from "./schemas/spart.schemas.js";
const app = express();
const PORT = 3000;
connect();
// ejs endeavor
app.set("view engine", "ejs");
app.set("views", "./views");
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
// ejs style and script
app.use(express.static("./style"));
app.use(express.static("./public"));
app.use((req, res, next) => {
console.log("Request URL:", req.originalUrl, "-", new Date());
next();
});
const router = express.Router();
// ejs 상품목록조회
app.get("/", async (req, res) => {
const products = await Spart.find()
.select("name thumbnailUrl price seller status createdAt")
.sort("-createdAt")
.exec();
res.render("index", { post: products });
});
// ejs 상품등록은 modal.js에서 바로 해당 경로로 fetch할 수 있음
app.use("/api", [router, spartRouter]);
app.use(errorHandler);
app.listen(PORT, () => {
console.log(PORT, "포트로 서버가 열렸어요!");
});
다 정상 작동됨...
[Node.js] sparamin 2 - Draft (AWS RDS / Express / MySQL / Prisma / yarn / JWT / winston / bcrypt / Thunder Client / ERD Cloud) (1) | 2024.02.02 |
---|---|
[Node.js] sparamin 1 - 공사중 (2) | 2024.01.31 |
[Node.js] Spart Store 1 (1) | 2024.01.23 |
[Node.js] NBC Movie Review 2 (4) | 2024.01.16 |
[Node.js] - NBC Movie Review 1 (1) | 2024.01.11 |