Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[강수정] sprint8 #24

Merged
merged 5 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as dotenv from "dotenv";
import express from "express";
import { PrismaClient } from "@prisma/client";
import router from "./router/index.js";
import cors from "cors";

dotenv.config();

const prisma = new PrismaClient();
const app = express();
app.use(express.json());
app.use(
cors({
origin: "*",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CORS의 origin: "*" 설정은 이렇게 공부할 때는 좋은데, 실무에서는 절대 이렇게 하지 마세요

})
);
//라우터 기본 세팅
app.use("/api", router);

//예시
// app.get("/good", (req, res) => {
// res.send("hi-");
// });

// //게시글 조회 API
// app.get("/article/:id", async (req, res) => {
// const { id } = req.params;
// console.log(id);
// /* id랑 같은거 user에 담는다. */
// const user = await prisma.article.findUnique({
// where: {
// id,
// },
// });
// });

const port = process.env.PORT || 8000;

app.listen(port, () => console.log(`Server Started :${port}`));
3 changes: 0 additions & 3 deletions back/.gitignore

This file was deleted.

122 changes: 0 additions & 122 deletions back/app.js

This file was deleted.

40 changes: 0 additions & 40 deletions back/data/mock.js

This file was deleted.

14 changes: 0 additions & 14 deletions back/data/seed.js

This file was deleted.

12 changes: 0 additions & 12 deletions back/request.http

This file was deleted.

22 changes: 22 additions & 0 deletions data/mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const MockData = [
{
title: "30분 운동",
content: "ㅇㅅㅇ",
},
{
title: "130분 운동",
content: "ㅠㅡㅠ",
},
{
title: "10분 운동",
content: "ㅇㅅ2222ㅇ",
},
{
title: "1022분 운동",
content: "ㅇㅅ2222ㅇ",
},
{
title: "10112분 운동",
content: "하늘나라",
},
];
Comment on lines +1 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

titlecontent에 큰 제한이 없다면, 그냥 랜덤생성하시는것도 좋습니다.

23 changes: 23 additions & 0 deletions data/seed.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 파일이 node.js에 의해 실행될 때는 mock.js 이외의 다른 파일과 무관하게, 독립적으로 실행된다는 점을 명심해주세요.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PrismaClient } from "@prisma/client";
import { MockData } from "./mock.js";

const prisma = new PrismaClient();

async function main() {
// 목 데이터 삽입
await prisma.article.createMany({
data: MockData,
skipDuplicates: true,
});
}

main()
.then(async () => {
await prisma.$disconnect();
console.log("success");
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading