-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
73 lines (62 loc) · 1.87 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
// express
const express = require("express");
const app = express();
const path = require('path');
const session = require('express-session');
const MySQLStore = require('express-mysql-session')(session);
const { username, password, database, host } = require('./config/config.json')['development'];
const sessionStore = new MySQLStore({
host: host,
port: 3306,
user: username,
password: password,
database: database,
});
app.use(session({
key: 'session_cookie_name',
secret: 'secret key',
resave: false,
saveUninitialized: true,
store: sessionStore,
}));
sessionStore.onReady().then(() => {
// MySQL session store ready for use.
console.log('MySQLStore 준비 완료');
}).catch(error => {
// Something went wrong.
console.error(error);
});
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.urlencoded({ extended: true }));
// view engine
app.set("view engine", "ejs");
app.set("views", "views");
// routes
const mainRoute = require('./routes/MainRoute');
const authRoute = require('./routes/AuthRoute');
const shopRoute = require('./routes/ShopRoute');
const cartRoute = require('./routes/CartRoute');
const adminRoute = require('./routes/AdminRoute');
app.use('/', mainRoute);
app.use('/auth', authRoute);
app.use('/shop', shopRoute);
app.use('/cart', cartRoute);
app.use('/admin', adminRoute);
// database
const sequelize = require('./models/index');
// const User = require('./models/User');
// const Product = require('./models/Product');
// const Cart = require('./models/Cart');
// User.hasMany(Product); // 1:N
// User.hasMany(Cart); // 1:N
// Product.hasMany(Cart); // 1:N
sequelize.sync({ force: false }) // force: true -> 테이블 재생성
.then(() => {
console.log('데이터베이스 연결 성공');
})
.catch((err) => {
console.error(err);
});
app.listen(3000, () => {
console.log("Server is running on port 3000");
});