Commit aa59e0a7 authored by Kim, Chaerin's avatar Kim, Chaerin
Browse files

서버 구축 완료

parent 9388ae9e
PG_DATABASE=boradb
PG_USER=test
PG_PASSWORD=test
\ No newline at end of file
PG_DATABASE=boraIt
PG_USER=postgres
PG_PASSWORD=postgres
\ No newline at end of file
node_modules/
package-lock.json
config/
env.development
\ No newline at end of file
const endpoints = {
API_BASE_URL: "https://localhost:8080/api",
HOME_API: "/",
ROOM_API: "/room",
PROFILE_API: "/profile",
HOME_API: "",
ROOM_API: "room",
PROFILE_API: "profile",
};
export default endpoints;
import axios from "axios";
import { API_BASE_URL } from "./endpoints";
import endpoints from "./endpoints";
const login = async (email, password) => {
const payload = { email, password };
const { data } = await axios.post(`${API_BASE_URL}/user`, payload);
const { data } = await axios.post(`${endpoints.API_BASE_URL}/`, payload);
return data;
};
......
import { useEffect, useState } from "react";
import login from "../apis/user.api";
const INIT_USER = {
id: "",
email: "",
password: "",
};
......@@ -26,7 +27,7 @@ const Login = () => {
try {
// setLoading(true);
// setError("");
// const success = await login(user.email, user.password);
const success = await login(user.email, user.password);
console.log(user);
setSuccess(success);
} catch (error) {
......@@ -36,7 +37,7 @@ const Login = () => {
}
}
const { id, password } = user;
const { email, password } = user;
return (
<div className="modal-content">
......@@ -57,11 +58,11 @@ const Login = () => {
<label>아이디</label>
<input
className="form-control"
id="id"
id="email"
type="text"
name="id"
name="email"
placeholder="아이디를 입력하세요"
value={id}
value={email}
onChange={handleChange}
/>
</div>
......
import { Room } from "../models/index.js";
import config from "../config/app.config.js";
const login = async (req, res) => {
try {
console.log("login= ", req.body);
res.json("안녕");
} catch (error) {
console.log(error);
return res.status(500).send("안녕 중 에러");
}
};
export default {
login,
};
import { User } from "../models/index.js";
import config from "../config/app.config.js";
const login = async (req, res) => {
try {
console.log("login= ", req.body);
const { email, password } = req.body;
const user = await User.scope("password").findOne({ where: email });
if (!user)
return res.status(422).send(`${email} 사용자가 존재하지 않습니다.`);
const passworMatch = await user.comparePassword(password);
if (passworMatch) {
const token = jwt.sign({ userID: user.id }, config.jwtSecret, {
expiresIn: config.jwtExpires,
});
res.cookie(config.cookieName, token, {
path: "/",
httpOnly: true,
secure: true,
});
res.json({ user });
} else {
res.status(401).send("비밀번호가 일치하지 않습니다.");
}
} catch (error) {
console.log(error);
return res.status(500).send("로그인 중 에러");
}
};
export default {
login,
};
......@@ -2,7 +2,7 @@
import dotenv from "dotenv";
import app from "./app.js";
import appConfig from "./config/app.config.js";
import { sequelize, User } from "./db/index.js";
import { sequelize, User } from "./models/index.js";
dotenv.config({
path: `${
......@@ -10,37 +10,59 @@ dotenv.config({
}`,
});
// production
// sequelize.sync().then(() => {
// app.listen(appConfig.port, () => {
// console.log(`Server is running on port ${appConfig.port}`)
// })
// })
// development
// 주의!!!: {force: true}는 서버가 다시 시작되면 기존 디비 모두 삭제되고 새로운 디비 생성
sequelize
.sync({ force: true })
.then(async () => {
// await Promise.all(
// Object.keys(ROLE_NAME).map((name) => {
// return Role.create({ name });
// })
// );
// const adminRole = await Role.findOne({ where: { name: "admin" } });
await User.create({
name: "admin",
id: "admin",
password: "admin!",
idNumber: "0000",
});
console.log(" DB 연결 성공");
// await User.create({
// id: 0,
// name: "admin",
// email: "admin",
// password: "admin!",
// gender: 0,
// });
app.listen(appConfig.port, () => {
console.log(`Server is running on port ${appConfig.port}`);
});
})
.catch((err) => {
console.log("연결 실패");
console.log(err);
});
// production
// sequelize.sync().then(() => {
// app.listen(appConfig.port, () => {
// console.log(`Server is running on port ${appConfig.port}`)
// })
// })
// development
// 주의!!!: {force: true}는 서버가 다시 시작되면 기존 디비 모두 삭제되고 새로운 디비 생성
// sequelize
// .sync({ force: true })
// .then(async () => {
// // await Promise.all(
// // Object.keys(ROLE_NAME).map((name) => {
// // return Role.create({ name });
// // })
// // );
// // const adminRole = await Role.findOne({ where: { name: "admin" } });
// await User.create({
// id: "0000",
// name: "admin",
// email: "admin",
// password: "admin!",
// gender: 0,
// });
// app.listen(appConfig.port, () => {
// console.log(`Server is running on port ${appConfig.port}`);
// });
// })
// .catch((err) => {
// console.log(err);
// });
import { Sequelize } from "sequelize";
import UserModel from "./user.model.js";
import RoomModel from "./room.model.js";
const env = process.env.NODE_ENV || "development";
import configs from "../config/config.js";
const config = configs[env];
const sequelize = new Sequelize(
config.database,
config.username,
config.password,
{ host: config.host, dialect: config.dialect }
);
const User = UserModel(sequelize);
const Room = RoomModel(sequelize);
export { sequelize, User, Room };
import bcrypt from "bcryptjs";
import { DataTypes } from "sequelize";
const RoomModel = (sequelize) => {
......
......@@ -4,8 +4,8 @@
"description": "Streaming Service",
"main": "index.js",
"scripts": {
"start": "nodemon server/index.js",
"dev": "nodemon -r esm server/index.js",
"start": "nodemon index.js",
"dev": "nodemon -r esm index.js",
"build": "tsc -p ."
},
"repository": {
......@@ -27,6 +27,7 @@
"nodemon": "^2.0.7",
"pg": "^8.6.0",
"pg-hstore": "^2.3.4",
"postgres": "^1.0.2",
"sequelize": "^6.6.5",
"socket.io": "2.3.0",
"wrtc": "0.4.6"
......
import express from "express";
import userRouter from "./user.route.js";
import roomRouter from "./room.route.js";
const router = express.Router();
router.use("/user", userRouter);
router.use("/", userRouter);
router.use("/room/:userId/:channelId", roomRouter);
export default router;
import express from "express";
// import authCrtl from "../controllers/auth.controller.js";
import roomCrtl from "../controllers/room.controller.js";
const router = express.Router();
// router.route("/").get(authCrtl.requireLogin);
router.route("/").get(roomCrtl.login);
export default router;
import express from "express";
// import authCrtl from "../controllers/auth.controller";
// import userCtrl from "../controllers/user.controller";
import userCtrl from "../controllers/user.controller.js";
const router = express.Router();
// router.route("/").get(authCrtl.requireLogin);
router.route("/").post(userCtrl.login);
export default router;
const config = {
env: process.env.NODE_ENV === 'production' ? 'production' : 'development',
port: process.env.PORT || 8080,
jwtSecret: 'ThisIsSecretKeyOFBoraIt!',
jwtExpires: '1d',
cookieName: 'borabora',
cookieMaxAge: 60 * 60 * 24 * 7 * 1000,
}
export default config
\ No newline at end of file
const config = {
host: 'localhost',
username: process.env.PG_USER || 'test',
password: process.env.PG_PASSWORD || 'test',
database: process.env.PG_DATABASE || 'testdb',
dialect: 'postgres',
pool: {
max: 10,
min: 0,
acquire: 30000,
idle: 10000,
}
}
export default config
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment