-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
82 lines (61 loc) · 2.03 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
import {authRouter} from './routes/admin/adminAuth.js';
import {appRouter} from './routes/app/appData.js';
import {adminRouter} from './routes/admin/adminData.js';
import {errorHandler} from "./middleware/errorHandler.js";
import {addRootUsers, setDefaultConfigs} from "./config/setupDB.js";
import {scheduleVerificationJob} from "./services/app/scheduleDB.js";
import express from 'express';
import passport from 'passport';
import session from 'express-session';
import connectSqlite3 from 'connect-sqlite3';
import cors from 'cors';
import {scheduleAutoRelease} from "./services/admin/scheduleRelease.js";
const SQLiteStore = connectSqlite3(session);
const app = express();
const corsOptions = {
origin: ["https://locker-api.cvapps.net", "https://locker.cvapps.net"],
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
};
// cors setup
app.use(cors(corsOptions));
// express middleware setup
app.use(express.urlencoded({extended: true}));
// Configure session with connect-sqlite3
app.use(
session({
store: new SQLiteStore({
db: './local-db/sessions.db',
}),
secret: process.env.SESSIONSECRET,
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 1800000, // Set the session timeout to 30 minutes (in milliseconds) 1800000
domain: '.cvapps.net',
},
})
);
// passport initialization
app.use(passport.initialize());
app.use(passport.session());
// setup express json middleware
app.use(express.json());
// define routes
app.use('/auth/', authRouter);
app.use('/public/', appRouter);
app.use('/admin/', adminRouter);
// global error handling middleware - must be at bottom of express stack
app.use(errorHandler);
// create root user
await addRootUsers();
// setup json configs in db
await setDefaultConfigs();
// start the verification queue scheduler
scheduleVerificationJob();
// start auto release scheduler
scheduleAutoRelease();
// Start the server
app.listen(3000, () => {
console.log(`Locker backend started`);
});