Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/efdevcon/monorepo into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
lassejaco committed Oct 26, 2024
2 parents 08cf246 + d441952 commit 04675a3
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 34 deletions.
5 changes: 3 additions & 2 deletions devcon-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@octokit/rest": "^19.0.7",
"@prisma/client": "^5.17.0",
"better-sqlite3": "^11.1.2",
"connect-pg-simple": "^10.0.0",
"cors": "^2.8.5",
"cross-fetch": "^3.1.5",
"csv-parser": "^3.0.0",
Expand All @@ -81,11 +82,10 @@
"jose": "^5.9.6",
"llamaindex": "^0.3.10",
"markdown-it": "^13.0.1",
"memorystore": "^1.6.7",
"natural": "^7.1.0",
"nodemailer": "^6.9.13",
"openai": "^4.55.5",
"pg": "^8.12.0",
"pg": "^8.13.1",
"puppeteer": "18.2.1",
"rate-limiter-flexible": "^5.0.3",
"remark": "^15.0.1",
Expand All @@ -104,6 +104,7 @@
"@octokit/types": "^9.0.0",
"@tsconfig/recommended": "^1.0.2",
"@types/better-sqlite3": "^7.6.11",
"@types/connect-pg-simple": "^7.0.3",
"@types/cors": "^2.8.13",
"@types/dotenv": "^8.2.0",
"@types/express": "^4.17.15",
Expand Down
10 changes: 6 additions & 4 deletions devcon-api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { notFoundHandler } from '@/middleware/notfound'
import { logHandler } from '@/middleware/log'
import { router } from './routes'
import { SERVER_CONFIG, SESSION_CONFIG } from '@/utils/config'
import createMemoryStore from 'memorystore'
import pgSession from 'connect-pg-simple'
import { getDbPool } from './utils/db'

const app = express()

Expand All @@ -27,15 +28,16 @@ app.use(
})
)

const store = createMemoryStore(session)
const pgSessionStore = pgSession(session)
const sessionConfig: SessionOptions = {
name: SESSION_CONFIG.cookieName,
secret: SESSION_CONFIG.password,
cookie: {},
resave: false,
saveUninitialized: true,
store: new store({
checkPeriod: 86400000, // prune expired entries every 24h
store: new pgSessionStore({
pool: getDbPool(),
tableName: 'Session',
}),
}

Expand Down
8 changes: 8 additions & 0 deletions devcon-api/src/db/account.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ model Account {
updatedAt DateTime?
}

model Session {
sid String @id @db.VarChar
sess Json
expire DateTime @db.Timestamp(6)
@@index([expire], name: "IDX_session_expire")
}

model rate_limit {
key String @id @db.VarChar(255)
points Int @default(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- CreateTable
CREATE TABLE "Session" (
"sid" VARCHAR NOT NULL,
"sess" JSONB NOT NULL,
"expire" TIMESTAMP(6) NOT NULL,

CONSTRAINT "Session_pkey" PRIMARY KEY ("sid")
);

-- CreateIndex
CREATE INDEX "IDX_session_expire" ON "Session"("expire");
38 changes: 38 additions & 0 deletions devcon-api/src/utils/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Pool, PoolConfig } from 'pg'
import { SERVER_CONFIG } from '@/utils/config'

let dbPool: Pool

export const DB_POOL_CONFIG: PoolConfig = {
connectionString: SERVER_CONFIG.DB_CONNECTION_STRING,
ssl:
SERVER_CONFIG.NODE_ENV === 'production'
? true
: {
rejectUnauthorized: false,
},
max: 20,
}

export function getDbPool() {
if (!dbPool) {
dbPool = new Pool(DB_POOL_CONFIG)

dbPool.on('error', (err) => {
console.error('Unexpected error on idle client', err)
})
}

return dbPool
}

export async function verify() {
const pool = getDbPool()

try {
const result = await pool.query('SELECT NOW()')
console.log('Db Connection established:', result.rows[0].now)
} catch (err) {
console.error('Error verifying database connection', err)
}
}
83 changes: 55 additions & 28 deletions devcon-api/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,15 @@
"@types/connect" "*"
"@types/node" "*"

"@types/connect-pg-simple@^7.0.3":
version "7.0.3"
resolved "https://registry.yarnpkg.com/@types/connect-pg-simple/-/connect-pg-simple-7.0.3.tgz#05b4bdbccbba333787b01730bacd202f15afa480"
integrity sha512-NGCy9WBlW2bw+J/QlLnFZ9WjoGs6tMo3LAut6mY4kK+XHzue//lpNVpAvYRpIwM969vBRAM2Re0izUvV6kt+NA==
dependencies:
"@types/express" "*"
"@types/express-session" "*"
"@types/pg" "*"

"@types/connect@*":
version "3.4.35"
resolved "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz"
Expand Down Expand Up @@ -1503,7 +1512,7 @@
"@types/qs" "*"
"@types/range-parser" "*"

"@types/express-session@^1.18.0":
"@types/express-session@*", "@types/express-session@^1.18.0":
version "1.18.0"
resolved "https://registry.yarnpkg.com/@types/express-session/-/express-session-1.18.0.tgz#7c6f25c3604b28d6bc08a2e3929997bbc7672fa2"
integrity sha512-27JdDRgor6PoYlURY+Y5kCakqp5ulC0kmf7y+QwaY+hv9jEFuQOThgkjyA53RP3jmKuBsH5GR6qEfFmvb8mwOA==
Expand Down Expand Up @@ -1671,6 +1680,15 @@
dependencies:
"@types/node" "*"

"@types/pg@*":
version "8.11.10"
resolved "https://registry.yarnpkg.com/@types/pg/-/pg-8.11.10.tgz#b8fb2b2b759d452fe3ec182beadd382563b63291"
integrity sha512-LczQUW4dbOQzsH2RQ5qoeJ6qJPdrcM/DcMLoqWQkMLMsq83J5lAX3LXjdkWdpscFy67JSOWDnh7Ny/sPFykmkg==
dependencies:
"@types/node" "*"
pg-protocol "*"
pg-types "^4.0.1"

"@types/pg@^8.11.6":
version "8.11.6"
resolved "https://registry.yarnpkg.com/@types/pg/-/pg-8.11.6.tgz#a2d0fb0a14b53951a17df5197401569fb9c0c54b"
Expand Down Expand Up @@ -2834,6 +2852,13 @@ [email protected]:
resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz"
integrity sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==

connect-pg-simple@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/connect-pg-simple/-/connect-pg-simple-10.0.0.tgz#972b08d9fc6a1861c523a6c9166240a24b4bc3ca"
integrity sha512-pBGVazlqiMrackzCr0eKhn4LO5trJXsOX0nQoey9wCOayh80MYtThCbq8eoLsjpiWgiok/h+1/uti9/2/Una8A==
dependencies:
pg "^8.12.0"

console-control-strings@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz"
Expand Down Expand Up @@ -2959,7 +2984,7 @@ [email protected]:
dependencies:
ms "2.0.0"

debug@4, [email protected], debug@^4.1.0, debug@^4.1.1, debug@^4.3.0, debug@^4.3.2, debug@^4.3.3, debug@^4.3.4:
debug@4, [email protected], debug@^4.1.0, debug@^4.1.1, debug@^4.3.2, debug@^4.3.3, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
Expand Down Expand Up @@ -5313,14 +5338,6 @@ lop@^0.4.1:
option "~0.2.1"
underscore "^1.13.1"

lru-cache@^4.0.3:
version "4.1.5"
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd"
integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==
dependencies:
pseudomap "^1.0.2"
yallist "^2.1.2"

lru-cache@^5.1.1:
version "5.1.1"
resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz"
Expand Down Expand Up @@ -5544,14 +5561,6 @@ memory-pager@^1.0.2:
resolved "https://registry.yarnpkg.com/memory-pager/-/memory-pager-1.5.0.tgz#d8751655d22d384682741c972f2c3d6dfa3e66b5"
integrity sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==

memorystore@^1.6.7:
version "1.6.7"
resolved "https://registry.yarnpkg.com/memorystore/-/memorystore-1.6.7.tgz#78f9b1c2b06949abfb4f85ec71f558ec4265e63d"
integrity sha512-OZnmNY/NDrKohPQ+hxp0muBcBKrzKNtHr55DbqSx9hLsYVNnomSAMRAtI7R64t3gf3ID7tHQA7mG4oL3Hu9hdw==
dependencies:
debug "^4.3.0"
lru-cache "^4.0.3"

[email protected]:
version "1.0.1"
resolved "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz"
Expand Down Expand Up @@ -6596,6 +6605,11 @@ pg-connection-string@^2.6.4:
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.6.4.tgz#f543862adfa49fa4e14bc8a8892d2a84d754246d"
integrity sha512-v+Z7W/0EO707aNMaAEfiGnGL9sxxumwLl2fJvCQtMn9Fxsg+lPpPkdcyBSv/KFgpGdYkMfn+EI1Or2EHjpgLCA==

pg-connection-string@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/pg-connection-string/-/pg-connection-string-2.7.0.tgz#f1d3489e427c62ece022dba98d5262efcb168b37"
integrity sha512-PI2W9mv53rXJQEOb8xNR8lH7Hr+EKa6oJa38zsK0S/ky2er16ios1wLKhZyxzD7jUReiWokc9WK5nxSnC7W1TA==

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/pg-int8/-/pg-int8-1.0.1.tgz#943bd463bf5b71b4170115f80f8efc9a0c0eb78c"
Expand All @@ -6611,11 +6625,21 @@ pg-pool@^3.6.2:
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.6.2.tgz#3a592370b8ae3f02a7c8130d245bc02fa2c5f3f2"
integrity sha512-Htjbg8BlwXqSBQ9V8Vjtc+vzf/6fVUuak/3/XXKA9oxZprwW3IMDQTGHP+KDmVL7rtd+R1QjbnCFPuTHm3G4hg==

pg-pool@^3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/pg-pool/-/pg-pool-3.7.0.tgz#d4d3c7ad640f8c6a2245adc369bafde4ebb8cbec"
integrity sha512-ZOBQForurqh4zZWjrgSwwAtzJ7QiRX0ovFkZr2klsen3Nm0aoh33Ls0fzfv3imeH/nw/O27cjdz5kzYJfeGp/g==

pg-protocol@*, pg-protocol@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.6.1.tgz#21333e6d83b01faaebfe7a33a7ad6bfd9ed38cb3"
integrity sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg==

pg-protocol@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/pg-protocol/-/pg-protocol-1.7.0.tgz#ec037c87c20515372692edac8b63cf4405448a93"
integrity sha512-hTK/mE36i8fDDhgDFjy6xNOG+LCorxLG3WO17tku+ij6sVHXh1jQUJ8hYAnRhNla4QVD2H8er/FOjc/+EgC6yQ==

pg-types@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/pg-types/-/pg-types-2.2.0.tgz#2d0250d636454f7cfa3b6ae0382fdfa8063254a3"
Expand Down Expand Up @@ -6653,6 +6677,19 @@ pg@^8.11.3, pg@^8.11.5, pg@^8.12.0:
optionalDependencies:
pg-cloudflare "^1.1.1"

pg@^8.13.1:
version "8.13.1"
resolved "https://registry.yarnpkg.com/pg/-/pg-8.13.1.tgz#6498d8b0a87ff76c2df7a32160309d3168c0c080"
integrity sha512-OUir1A0rPNZlX//c7ksiu7crsGZTKSOXJPgtNiHGIlC9H0lO+NC6ZDYksSgBYY/thSWhnSRBv8w1lieNNGATNQ==
dependencies:
pg-connection-string "^2.7.0"
pg-pool "^3.7.0"
pg-protocol "^1.7.0"
pg-types "^2.1.0"
pgpass "1.x"
optionalDependencies:
pg-cloudflare "^1.1.1"

[email protected]:
version "1.0.5"
resolved "https://registry.yarnpkg.com/pgpass/-/pgpass-1.0.5.tgz#9b873e4a564bb10fa7a7dbd55312728d422a223d"
Expand Down Expand Up @@ -6920,11 +6957,6 @@ [email protected], proxy-from-env@^1.1.0:
resolved "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
integrity sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ==

psl@^1.1.33:
version "1.9.0"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7"
Expand Down Expand Up @@ -8716,11 +8748,6 @@ [email protected], yallist@^4.0.0:
resolved "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz"
integrity sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==

yallist@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52"
integrity sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A==

yallist@^3.0.2:
version "3.1.1"
resolved "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz"
Expand Down

0 comments on commit 04675a3

Please sign in to comment.