index.js 1.88 KB
Newer Older
Kim, Chaerin's avatar
Kim, Chaerin committed
1
2
3
4
// server 진입점
import dotenv from "dotenv";
import app from "./app.js";
import appConfig from "./config/app.config.js";
우지원's avatar
e    
우지원 committed
5
import { Room, sequelize, User } from "./models/index.js";
Kim, Chaerin's avatar
Kim, Chaerin committed
6
7
8
9
10
11
12
13
14
15
16

dotenv.config({
  path: `${
    process.env.NODE_ENV === "production" ? ".env" : ".env.development"
  }`,
});

sequelize
  .sync({ force: true })
  .then(async () => {
    console.log(" DB 연결 성공");
Kim, Chaerin's avatar
.    
Kim, Chaerin committed
17
    await User.create({
우지원's avatar
e    
우지원 committed
18
      id: "9999",
Kim, Chaerin's avatar
.    
Kim, Chaerin committed
19
20
21
22
23
      name: "admin",
      email: "admin",
      password: "admin!",
      gender: 0,
    });
Kim, Chaerin's avatar
Kim, Chaerin committed
24

우지원's avatar
e    
우지원 committed
25
26
27
28
29
30
31
32
33
    await Room.create({
      id: "1234567890",
      name: "room",
      owner: [ '600112d16d09ac6b7892d900' ],
      member: [ '600112d16d09ac6b7892d900' ],
      profileimg: "C:\fakepath\스크린샷(1).png",
      channel: [ '회의' ],
    });

Kim, Chaerin's avatar
Kim, Chaerin committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
    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);
//   });