Consistend capitalization
This commit is contained in:
parent
e6b9ad9262
commit
07bedda2c0
@ -1,3 +1,3 @@
|
||||
module.exports = {
|
||||
jwt_secret: process.env.JWT_SECRET
|
||||
JWT_SECRET: process.env.JWT_SECRET
|
||||
};
|
||||
@ -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
|
||||
};
|
||||
@ -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,
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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}`);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user