first commit
This commit is contained in:
23
config/init.js
Normal file
23
config/init.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const {default: rateLimit} = require("express-rate-limit");
|
||||
const path = require("path");
|
||||
require("dotenv").config();
|
||||
module.exports = {
|
||||
PORT: process.env.PORT || 4000,
|
||||
JWT_SECRET:
|
||||
process.env.JWT_SECRET || "dasdG23qewqe1234441fFGfdhdghnnbCCZXQSDQWEweqwe",
|
||||
STORAGE_PATH: path.resolve(__dirname, "../uploads"),
|
||||
MAX_FILE_SIZE: 5 * 1024 * 1024, // 5MB
|
||||
ALLOWED_FILE_TYPES: ["image/jpeg", "image/png", "image/webp"], // نوعهای مجاز
|
||||
limiter: rateLimit({
|
||||
windowMs: 5 * 60 * 1000, // 5 دقیقه
|
||||
max: 30,
|
||||
standardHeaders: true, // Return rate limit info in `RateLimit-*` headers
|
||||
legacyHeaders: false, // Disable the `X-RateLimit-*` headers
|
||||
handler: (req, res) => {
|
||||
res.status(500).json({
|
||||
status: 500,
|
||||
message: "تعداد درخواست ها بیش تر از حد مجاز، در فرصتی دیگر تلاش کنید",
|
||||
});
|
||||
},
|
||||
}),
|
||||
};
|
||||
17
config/logger.js
Normal file
17
config/logger.js
Normal file
@@ -0,0 +1,17 @@
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const winston = require("winston");
|
||||
const logDirectory = path.join(__dirname, "..", "logs");
|
||||
if (!fs.existsSync(logDirectory)) {
|
||||
fs.mkdirSync(logDirectory);
|
||||
}
|
||||
const logger = winston.createLogger({
|
||||
level: "info",
|
||||
format: winston.format?.json(),
|
||||
|
||||
transports: [
|
||||
new winston.transports.File({filename: path.join(logDirectory, "cdn.log")}),
|
||||
],
|
||||
});
|
||||
|
||||
module.exports = logger;
|
||||
Reference in New Issue
Block a user