forked from YoJuemGutDuel/Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
62 lines (45 loc) · 1.5 KB
/
index.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
import { createRequire } from "module";
const require = createRequire(import.meta.url); //import와 require 동시에 사용
import express from "express";
import cookieParser from "cookie-parser";
import redisCli from "./modules/redis.js";
import routes from './routes/index.js';
import config from './config/index.js';
import cors from 'cors';
import analyEmotion from "./modules/analyEmotion.js";
import { scheduleJob } from "node-schedule";
const mongoose = require("mongoose");
const app = express()
let corsOptions = {
origin: '*', //출처 허용 옵션
};
app.use(cors(corsOptions));
app.use(cookieParser());
app.use(express.json()); //JSON 문자열이 넘어오는 경우 객체로 변환
app.use(express.urlencoded({ extended: false })); //요청 본문의 데이터를 req.body 객체로 생성
app.use("/", routes);
app.get("/", (req, res, next) => {
res.send('Hello World!');
});
mongoose
.connect(config.mongoURI, {
dbName: 'YoJuemGutDuel',
})
.then(() => console.log("MongoDB Connected..."))
.catch((err) => console.log(err))
mongoose.set("strictQuery", false);
scheduleJob('0 33 1 * * *', function () {
console.log('업데이트');
analyEmotion()
.then((res) => console.log("성공", res));
});
app.listen(config.port, () => {
console.log(`
################################################
🛡️ Server listening on ${config.port}🛡️
################################################
`);
});
export default {
app
};