-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
63 lines (56 loc) · 1.68 KB
/
index.ts
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
import dotenv from 'dotenv';
dotenv.config();
import express from 'express';
import cors from 'cors';
import session from 'express-session';
import mysql from 'mysql';
import {sqlOptions} from './sql/connection';
import expressMysqlSession from 'express-mysql-session';
const mySqlStore = expressMysqlSession(session as any); // ????
import registration from './routes/registration/Registration';
import i18next from './multilanguage/i18n';
import middleware from 'i18next-http-middleware';
import todo from './routes/todo/Todo';
import logout from './routes/logout/Logout';
import forgotPass from './routes/forgot-pass/ForgotPass';
import login from './routes/login/Login';
import changePass from './routes/change-pass/ChangePass';
import user from './routes/user/User';
const app = express();
app.use(cors({credentials: true, origin: true}));
app.use(express.json());
app.use(express.urlencoded({extended: true}));
const sessionConnection = mysql.createPool(sqlOptions);
const sessionStore = new mySqlStore({
createDatabaseTable: true,
schema: {
tableName: 'session',
columnNames: {
session_id: 'session_id',
expires: 'expires',
data: 'data',
},
},
}, sessionConnection);
app.use(session({
name: 'sid',
secret: process.env.SESSION_SALT!,
store: sessionStore,
resave: true,
rolling: true,
saveUninitialized: false,
proxy: true,
cookie: {
maxAge: 1000 * 30 * 60 * 24 * 7 * 4, // 4 weeks
httpOnly: true,
sameSite: 'none',
secure: true,
},
}),
);
app.use(middleware.handle(i18next));
app.use('/api', todo, logout, forgotPass, changePass, login, registration, user);
const port = process.env.PORT ?? 3002;
app.listen(port, () => {
console.log(`Listening on port ${port}...`);
});