forked from Cheese-Guardians/cheese
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
91 lines (72 loc) · 2.36 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//connect database
require('dotenv').config({path: "./config/database.env"});
const mysql = require ('mysql2');
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PW,
port: process.env.DB_PORT,
database: process.env.DB_NAME,
waitForConnections: true,
insecureAuth: true,
charset: 'utf8mb4'
});
module.exports = pool; //모듈로 내보내기
// 스케줄링을 위한 패키지 추가
const schedule = require('node-schedule');
require('dotenv').config({path: "./config/sens.env"}); // sens.env 불러오기
require('dotenv').config({path: "./config/gpt.env"}); // gpt.env 불러오기
// 기본 설정
const port = 3000,
express = require("express"),
cors = require("cors")
app = express(),
fs = require("fs"),
layouts = require("express-ejs-layouts"),
calendarRouter = require('./routes/calendarRoute'),
usersRouter = require('./routes/usersRoute'),
reminderRouter = require('./routes/reminderRoute'),
communityRouter = require('./routes/communityRoute'),
sanitizeHtml = require('sanitize-html'),
exportRouter = require('./routes/exportRoute'),
puppeteer = require('puppeteer');
const cookieParser = require('cookie-parser');
app.set("view engine", "ejs");
app.use(express.static("public/"));
app.use('/uploads',express.static("uploads/"));
app.use(layouts);
app.use(express.urlencoded());
app.use(express.json());
app.use(cookieParser());
//라우터 등록
app.use('/calendar', calendarRouter);
app.use('/users', usersRouter);
app.use('/reminder', reminderRouter);
app.use('/community', communityRouter)
app.use('/export', exportRouter);
reminderController = require('./controllers/reminderController');
//주기적인 작업 스케줄링
schedule.scheduleJob('* * * * *', function() { //1분
reminderController.sendSMS();
});
// root - 로그인
app.get(
"/", (req,res) =>
{res.render("users/login.ejs");}
);
app.listen(port,() => {
const dir = "./uploads";
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
console.log("서버 실행 중");
}
);
// const spawn = require('child_process').spawn;
// const result = spawn('python', ['graph.py'));
// result.stdout.on('data', function(data) {
// console.log(data.toString());
// });
// result.stderr.on('data', function(data) {
// console.log(data.toString());
// });