Config fiddling

This commit is contained in:
Apher 2026-06-28 23:00:25 +00:00
parent c646fefec1
commit d0199b5a91
2 changed files with 8 additions and 7 deletions

View File

@ -1,3 +1,3 @@
module.exports = { module.exports = {
secret: process.env.JWT_SECRET jwt_secret: process.env.JWT_SECRET
}; };

View File

@ -19,22 +19,22 @@ const createApp = () => {
// CORS restrict in production (set ALLOWED_ORIGINS env to comma-separated list) // CORS restrict in production (set ALLOWED_ORIGINS env to comma-separated list)
const corsOptions = { const corsOptions = {
origin: config.NODE_ENV === "production" origin: config.node_env === "production"
? (config.ALLOWED_ORIGINS || "").split(",").map(s => s.trim()) ? (config.allowed_origins || "").split(",").map(s => s.trim())
: true, : true,
optionsSuccessStatus: 200 optionsSuccessStatus: 200
}; };
app.use(cors(corsOptions)); app.use(cors(corsOptions));
// Logging verbose in dev // Logging verbose in dev
app.use(morgan(config.NODE_ENV === "production" ? "combined" : "dev")); app.use(morgan(config.node_env === "production" ? "combined" : "dev"));
// Body parsing with size limits // Body parsing with size limits
app.use(express.json({limit: "10kb"})); app.use(express.json({limit: "10kb"}));
app.use(express.urlencoded({extended: false, limit: "10kb"})); app.use(express.urlencoded({extended: false, limit: "10kb"}));
// Apply rate limiting in production // Apply rate limiting in production
if (config.NODE_ENV === "production") { if (config.node_env === "production") {
app.use(rateLimit({ app.use(rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit per IP max: 100, // limit per IP
@ -75,12 +75,13 @@ const initRoles = async () => {
const start = async () => { const start = async () => {
try { try {
// Validate important env vars // Validate important env vars
console.log(authConfig.jwt_secret);
if (!authConfig.secret) { if (!authConfig.secret) {
console.warn("JWT_SECRET not set. Ensure secure secret in production."); console.warn("JWT_SECRET not set. Ensure secure secret in production.");
} }
// Sync DB (not forced in production) // Sync DB (not forced in production)
const doForce = config.FORCE_DB_SYNC === "true" && config.NODE_ENV !== "production"; const doForce = config.force_db_sync === "true" && config.node_env !== "production";
await sequelize.authenticate(); await sequelize.authenticate();
await sequelize.sync({force: doForce}); await sequelize.sync({force: doForce});
if (doForce) console.info("Database dropped and resynced (force=true)."); if (doForce) console.info("Database dropped and resynced (force=true).");
@ -90,7 +91,7 @@ const start = async () => {
const app = createApp(); const app = createApp();
// Set port and listen // Set port and listen
const PORT = parseInt(config.PORT, 10) || 5000; const PORT = parseInt(config.port, 10) || 5000;
const server = app.listen(PORT, () => { const server = app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`); console.log(`Server listening on port ${PORT}`);
}); });