forked from gusdnvkfks/LegoMore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from gusdnvkfks/dev
[Common] add: deploy
- Loading branch information
Showing
6 changed files
with
123 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { user } = require("../../models"); | ||
|
||
module.exports = (res, req) => { | ||
const userInfo = user.destroy({ | ||
where: { id: 1 }, | ||
}); | ||
|
||
console.log(userInfo); | ||
|
||
res | ||
// .cookie("jwt", null, { maxAge: 0 }) | ||
.status(200) | ||
.json({ id: 1 }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = (res, req) => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,45 @@ | ||
module.exports = (req, res) => {}; | ||
const { user } = require("../../models"); | ||
const { generateAccessToken } = require("../tokenFunctions"); | ||
|
||
module.exports = (req, res) => { | ||
const userInfo = req.body; | ||
if ( | ||
userInfo.email === undefined || | ||
req.body.nickname === undefined || | ||
req.body.password === undefined | ||
) { | ||
res.status(400).send({ message: "잘못된 요청" }); | ||
} else { | ||
user | ||
.findOrCreate({ | ||
where: { email: userInfo.email }, | ||
defaults: { password: userInfo.password, nickname: userInfo.nickname }, | ||
}) | ||
.then(([users, created]) => { | ||
// created - true => 11번째줄 where에 해당하는 email이 없어서 새로 만들어줌. | ||
// created - false => 11번째줄에 where에 해당하는 email이 있어서 만들지 않음. | ||
if (created) { | ||
const payload = { | ||
// 추후에 데이터를 받아오는것 보고 수정 | ||
id: users.dataValues.id, | ||
email: users.dataValues.email, | ||
nickname: users.dataValues.nickname, | ||
createdAt: users.dataValues.createdAt, | ||
updatedAt: users.dataValues.updatedAt, | ||
}; | ||
|
||
const token = generateAccessToken(payload); | ||
res | ||
.cookie("jwt", token, { | ||
httpOnly: true, | ||
sameSite: "none", | ||
secure: true, | ||
}) | ||
.status(201) | ||
.send({ message: "Ok" }); | ||
} else { | ||
res.status(409).send({ message: "Email Exists" }); | ||
} | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,43 @@ | ||
// const express = require("express"); | ||
// const app = express(); | ||
// const cors = require("cors"); | ||
// const cookieParser = require("cookie-parser"); | ||
// const port = 4000; | ||
|
||
// const controllers = require("./controllers"); | ||
|
||
// app.use(express.json()); | ||
// // 좀 찾아보기로 밑에꺼 | ||
// app.use(express.urlencoded({ extended: false })); | ||
// app.use( | ||
// cors({ | ||
// origin: "*", | ||
// credentials: true, | ||
// methods: ["GET", "POST", "OPTION", "PUT"], | ||
// }) | ||
// ); | ||
|
||
// app.use(cookieParser()); | ||
// app.get("/:id", controllers.auth); | ||
// app.delete("/:id", controllers.delete); | ||
// app.put("/:id", controllers.put); | ||
// app.post("/signup", controllers.signup); | ||
// app.post("/signin", controllers.signin); | ||
// app.post("/signout", controllers.signout); | ||
|
||
// module.exports = app.listen(port, () => { | ||
// console.log(` Server is starting on ${port}`); | ||
// }); | ||
|
||
const express = require("express"); | ||
const app = express(); | ||
const cors = require("cors"); | ||
const cookieParser = require("cookie-parser"); | ||
|
||
const port = 4000; | ||
|
||
const controllers = require("./controller"); | ||
|
||
app.use(express.json()); | ||
// 좀 찾아보기로 밑에꺼 | ||
app.use(express.urlencoded({ extended: false })); | ||
app.use( | ||
cors({ | ||
origin: "*", | ||
credentials: true, | ||
methods: ["GET", "POST", "OPTION", "PUT"], | ||
}) | ||
); | ||
|
||
app.use(cookieParser()); | ||
app.get("/auth", controllers.auth); | ||
app.post("/signup", controllers.signup); | ||
app.post("/signin", controllers.signin); | ||
app.post("/signout", controllers.signout); | ||
|
||
module.exports = app.listen(port, () => { | ||
console.log(` Server is starting on ${port}`); | ||
app.get("/", (req, res) => { | ||
res.send("Hello World"); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log("성공"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters