const fs = require('fs') const path = require('path') // Load local secrets from server/.env (gitignored). Never commit this file. function loadEnv() { const file = path.join(__dirname, '.env') if (!fs.existsSync(file)) return fs.readFileSync(file, 'utf8') .split('\n') .forEach((line) => { const text = line.trim() if (!text || text.startsWith('#')) return const i = text.indexOf('=') if (i < 1) return const key = text.slice(0, i).trim() let value = text.slice(i + 1).trim() if ( (value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")) ) { value = value.slice(1, -1) } if (!process.env[key]) process.env[key] = value }) } loadEnv() const app = require('./app') const db = require('./lib/db') const PORT = Number(process.env.PORT) || 3000 db.read() app.listen(PORT, () => { console.log(`卓米会服务已启动 http://localhost:${PORT}`) console.log(`管理后台 http://localhost:${PORT}/admin`) if (!process.env.WX_APPID || !process.env.WX_SECRET) { console.log('未配置 WX_APPID / WX_SECRET,小程序登录走演示模式') } else { console.log(`微信登录已启用 AppID ${process.env.WX_APPID}`) } })