Add data layer with MongoDB and JSON fallback store

Introduce database config, MongoDB and JSON store implementations,
and a datastore factory that connects to MongoDB by default and falls
back to a local JSON file when MongoDB is unavailable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
francesco448
2026-03-18 16:52:34 +01:00
parent 3e3fa11951
commit e0d53d6e74
5 changed files with 455 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
const fs = require('fs')
const path = require('path')
loadLocalEnv()
module.exports = {
port: process.env.PORT || 4000,
clientOrigin: process.env.CLIENT_ORIGIN || '*',
}
function loadLocalEnv() {
const envPath = path.join(__dirname, '..', '.env')
if (!fs.existsSync(envPath)) {
return
}
const content = fs.readFileSync(envPath, 'utf-8')
for (const line of content.split(/\r?\n/)) {
if (!line || line.trim().startsWith('#')) continue
const [key, ...rest] = line.split('=')
if (!key) continue
const value = rest.join('=').trim()
if (key && value && process.env[key] === undefined) {
process.env[key] = value
}
}
}