-
Notifications
You must be signed in to change notification settings - Fork 15
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
[강수정] sprint8 #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: "*", | ||
}) | ||
); | ||
//라우터 기본 세팅 | ||
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}`)); |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CORS의
origin: "*"
설정은 이렇게 공부할 때는 좋은데, 실무에서는 절대 이렇게 하지 마세요