Config fiddling
This commit is contained in:
parent
c646fefec1
commit
d0199b5a91
@ -1,3 +1,3 @@
|
||||
module.exports = {
|
||||
secret: process.env.JWT_SECRET
|
||||
jwt_secret: process.env.JWT_SECRET
|
||||
};
|
||||
@ -19,22 +19,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
|
||||
@ -75,12 +75,13 @@ const initRoles = async () => {
|
||||
const start = async () => {
|
||||
try {
|
||||
// Validate important env vars
|
||||
console.log(authConfig.jwt_secret);
|
||||
if (!authConfig.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).");
|
||||
@ -90,7 +91,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