From 07bedda2c0069e42e2d6e7326d715a89de924bd2 Mon Sep 17 00:00:00 2001 From: Apher Date: Mon, 29 Jun 2026 00:32:16 +0000 Subject: [PATCH] Consistend capitalization --- src/config/auth.config.js | 2 +- src/config/index.js | 7 ++++--- src/controllers/auth.controller.js | 2 +- src/middleware/authJwt.js | 2 +- src/server.js | 14 +++++++------- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/config/auth.config.js b/src/config/auth.config.js index 678568a..cc5459d 100644 --- a/src/config/auth.config.js +++ b/src/config/auth.config.js @@ -1,3 +1,3 @@ module.exports = { - jwt_secret: process.env.JWT_SECRET + JWT_SECRET: process.env.JWT_SECRET }; \ No newline at end of file diff --git a/src/config/index.js b/src/config/index.js index c45ca2c..9890268 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -1,5 +1,6 @@ module.exports = { - force_db_sync: process.env.FORCE_DB_SYNC, - node_env: process.env.NODE_ENV, - port: process.env.PORT + FORCE_DB_SYNC: process.env.FORCE_DB_SYNC, + NODE_ENV: process.env.NODE_ENV, + PORT: process.env.PORT, + DEVICE_ID: process.env.DEVICE_ID }; \ No newline at end of file diff --git a/src/controllers/auth.controller.js b/src/controllers/auth.controller.js index 04f61bd..2b78639 100644 --- a/src/controllers/auth.controller.js +++ b/src/controllers/auth.controller.js @@ -74,7 +74,7 @@ exports.signin = async (req, res) => { const token = jwt.sign( {id: user.id}, - config.secret, + config.JWT_SECRET, { algorithm: "HS256", allowInsecureKeySizes: true, diff --git a/src/middleware/authJwt.js b/src/middleware/authJwt.js index 3391086..3bb0f52 100644 --- a/src/middleware/authJwt.js +++ b/src/middleware/authJwt.js @@ -9,7 +9,7 @@ verifyToken = (req, res, next) => { if (!token) return res.status(403).send({message: "No token provided!"}); const raw = token.startsWith("Bearer ") ? token.slice(7) : token; - jwt.verify(raw, config.secret, (err, decoded) => { + jwt.verify(raw, config.JWT_SECRET, (err, decoded) => { if (err) return res.status(401).send({message: "Unauthorized!",}); req.userId = decoded.id; next(); diff --git a/src/server.js b/src/server.js index c09a7ee..0ab3ddc 100644 --- a/src/server.js +++ b/src/server.js @@ -23,22 +23,22 @@ const createApp = () => { // CORS restrict in production (set ALLOWED_ORIGINS env to comma-separated list) const corsOptions = { - origin: config.node_env === "production" - ? (config.allowed_origins || "").split(",").map(s => s.trim()) + origin: config.NODE_ENV === "production" + ? (config.ALLOWED_ORIGINS || "").split(",").map(s => s.trim()) : true, optionsSuccessStatus: 200 }; app.use(cors(corsOptions)); // 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 app.use(express.json({limit: "10kb"})); app.use(express.urlencoded({extended: false, limit: "10kb"})); // Apply rate limiting in production - if (config.node_env === "production") { + if (config.NODE_ENV === "production") { app.use(rateLimit({ windowMs: 15 * 60 * 1000, // 15 minutes max: 100, // limit per IP @@ -79,12 +79,12 @@ const initRoles = async () => { const start = async () => { try { // Validate important env vars - if (!authConfig.jwt_secret) { + if (!authConfig.JWT_SECRET) { console.warn("JWT_SECRET not set. Ensure secure secret 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.sync({force: doForce}); if (doForce) console.info("Database dropped and resynced (force=true)."); @@ -94,7 +94,7 @@ const start = async () => { const app = createApp(); // Set port and listen - const PORT = parseInt(config.port, 10) || 5000; + const PORT = parseInt(config.PORT, 10) || 5000; const server = app.listen(PORT, () => { console.log(`Server listening on port ${PORT}`); });