This repository has been archived by the owner on Aug 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
72 lines (58 loc) · 1.91 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
63
64
65
66
67
68
69
70
71
72
const express = require('express');
const cors = require('cors');
const path = require('path');
const passport = require('passport');
const { PrismaSessionStore } = require('@quixo3/prisma-session-store');
var session = require('express-session')
const { PrismaClient } = require('@prisma/client')
const prisma = new PrismaClient()
require('dotenv').config()
/**
* -------------- GENERAL SETUP ----------------
*/
// Gives us access to variables set in the .env file via `process.env.VARIABLE_NAME` syntax
require('dotenv').config();
// Create the Express application
var app = express();
// Pass the global passport object into the configuration function
require('./config/passport')(passport);
// This will initialize the passport object on every request
app.use(session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: true,
store: new PrismaSessionStore(
new PrismaClient(),
{
checkPeriod: 2 * 60 * 1000, //ms
dbRecordIdIsSessionId: true,
dbRecordIdFunction: undefined,
}
)
}))
app.use(passport.initialize());
app.use(passport.session())
// Instead of using body-parser middleware, use the new Express implementation of the same thing
app.use(express.json());
app.use(express.urlencoded({extended: true}));
// Allows our Angular application to make HTTP requests to Express application
app.use(cors());
/**
* -------------- ROUTES ----------------
*/
// Imports all of the routes from ./routes/index.js
const auth = require('./routes/auth');
const user = require('./routes/user');
const filters = require('./routes/filters');
const notifications = require('./routes/notifications');
app.use(auth);
app.use(user);
app.use('/filters', filters);
app.use('/push', notifications);
/**
* -------------- SERVER ----------------
*/
// Server listens on http://localhost:3002
app.listen(3002, () => {
console.log('Server listening on http://localhost:3002');
})