e0d53d6e74
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>
30 lines
668 B
JavaScript
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
|
|
}
|
|
}
|
|
}
|