-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnections.js
50 lines (44 loc) · 1.28 KB
/
connections.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
import { RedisClient, createClient } from "redis";
import { each } from "async";
import connectRedis from "connect-redis";
import session from "express-session";
import sgMail from "@sendgrid/mail";
import pgPromise from "pg-promise";
const pgp = pgPromise({});
const RedisStore = connectRedis(session);
//SENDGRID
sgMail.setApiKey(process.env.SGAPIKEY);
//REDIS || Sessions
const client = createClient(process.env.REDIS_URL);
client.on("error", (err) => {
console.log(err);
});
const sess = session({
store: new RedisStore({ client: client }),
secret: process.env.SECRET,
resave: false,
saveUninitialized: false,
cookie: {
secure: false, // if true only transmit cookie over https
httpOnly: false, // if true prevent client side JS from reading the cookie
maxAge: 1000 * 60 * 10, // session max age in miliseconds
},
});
// --------ENVIRONMENT PGSQL----------
const db = pgp({
connectionString: process.env.DATABASE_URL,
ssl: { rejectUnauthorized: false },
});
RedisClient.prototype.delWildcard = function (key, callback) {
var redis = this;
redis.keys(key, function (err, rows) {
each(
rows,
function (row, callbackDelete) {
redis.del(row, callbackDelete);
},
callback
);
});
};
export { client, sess, db, RedisStore, sgMail };