Consistend capitalization

This commit is contained in:
Apher 2026-06-29 00:32:16 +00:00
parent e6b9ad9262
commit 07bedda2c0
5 changed files with 14 additions and 13 deletions

View File

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

View File

@ -1,5 +1,6 @@
module.exports = { module.exports = {
force_db_sync: process.env.FORCE_DB_SYNC, FORCE_DB_SYNC: process.env.FORCE_DB_SYNC,
node_env: process.env.NODE_ENV, NODE_ENV: process.env.NODE_ENV,
port: process.env.PORT PORT: process.env.PORT,
DEVICE_ID: process.env.DEVICE_ID
}; };

View File

@ -74,7 +74,7 @@ exports.signin = async (req, res) => {
const token = jwt.sign( const token = jwt.sign(
{id: user.id}, {id: user.id},
config.secret, config.JWT_SECRET,
{ {
algorithm: "HS256", algorithm: "HS256",
allowInsecureKeySizes: true, allowInsecureKeySizes: true,

View File

@ -9,7 +9,7 @@ verifyToken = (req, res, next) => {
if (!token) return res.status(403).send({message: "No token provided!"}); if (!token) return res.status(403).send({message: "No token provided!"});
const raw = token.startsWith("Bearer ") ? token.slice(7) : token; 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!",}); if (err) return res.status(401).send({message: "Unauthorized!",});
req.userId = decoded.id; req.userId = decoded.id;
next(); next();

View File

@ -23,22 +23,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
@ -79,12 +79,12 @@ const initRoles = async () => {
const start = async () => { const start = async () => {
try { try {
// Validate important env vars // Validate important env vars
if (!authConfig.jwt_secret) { if (!authConfig.JWT_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).");
@ -94,7 +94,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}`);
}); });