-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
86 lines (70 loc) · 2.16 KB
/
app.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
const dotenv = require('dotenv');
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const session = require('express-session');
const http = require('http');
const MySQLStore = require('express-mysql-session')(session);
dotenv.config();
const {sequelize} = require('./models');
const env = process.env.DATA_ENV || 'development';
const config = require('./config/config.js')[env];
const app = express();
const indexRouter = require('./src/routes/');
const userRouter = require('./src/routes/user');
const postRouter = require('./src/routes/post');
const noteRouter = require('./src/routes/note');
const sessionMiddleware = session({
key : 'login',
secret:process.env.COOKIE_SECRET,
resave: false,
saveUninitialized: true,
rolling : true,
store: new MySQLStore({
host : config.host,
port : 3306,
user : config.user,
clearExpired: true,
checkExpirationInterval: 30000,
password : config.password,
database: config.database,
}),
cookie: {
maxAge : 0,
expires : new Date(Date.now() + 36000000000)
}
});
app.set('port', 8000);
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(sessionMiddleware);
app.use(cors());
app.set('trust proxy',1);
app.use("/", indexRouter);
app.use("/user", userRouter);
app.use("/posting", postRouter);
app.use("/note", noteRouter);
app.post("/test", async (req, res) => {
const Space = require('./models/space.js');
const User = require('./models/user.js');
const tmp = await Space.create();
const user = await User.findOne({
where : {
id : 1
}
});
await tmp.addUser(user);
res.status(200).json({msg: 'Non User'});
});
const httpserver = http.createServer(app);
httpserver.listen(app.get('port'), async() => {
console.log(app.get('port'), '번 포트에서 대기중');
await sequelize
.sync({ force: false })
.then(async () => {
console.log("데이터베이스 연결 됨");
})
.catch((error) => {
console.log(error);
});
});