Files
Chatapp/Backend/config/index.js
T
francesco448 e0d53d6e74 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>
2026-03-18 16:52:34 +01:00

30 lines
668 B
JavaScript

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
}
}
}