Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Khalid1G committed Jun 22, 2023
2 parents be73f7d + d9ae2c6 commit 17e53a5
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 34 deletions.
3 changes: 2 additions & 1 deletion backend-app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ADMIN_EMAIL = "admin@swf.com"
ADMIN_PASSWORD = "password123418746"
JWT_SECRET = "JWT-Seceret-Key"
JWT_EXPIRES_IN = "1y"
PORT = 5000
PORT = 5000
RATE_LIMIT_PER_HOUR = 500
82 changes: 82 additions & 0 deletions backend-app/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"extends": ["eslint:recommended"],
"parserOptions": {
"ecmaVersion": 2021
},
"rules": {
"accessor-pairs": "error",
"array-callback-return": "error",
"block-scoped-var": "error",
"class-methods-use-this": "error",
"complexity": ["error", 10],
"consistent-return": "error",
"default-case": "error",
"dot-location": ["error", "property"],
"dot-notation": "error",
"eqeqeq": "error",
"guard-for-in": "error",
"max-classes-per-file": ["error", 1],
"no-alert": "error",
"no-caller": "error",
"no-case-declarations": "error",
"no-div-regex": "error",
"no-else-return": "error",
"no-empty-function": "error",
"no-empty-pattern": "error",
"no-eq-null": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-fallthrough": "error",
"no-floating-decimal": "error",
"no-global-assign": "error",
"no-native-reassign": "error",
"no-implied-eval": "error",
"no-invalid-this": "error",
"no-iterator": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-loop-func": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-proto": "error",
"no-redeclare": "error",
"no-return-assign": "error",
"no-return-await": "error",
"no-script-url": "error",
"no-self-assign": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-throw-literal": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-unused-labels": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"no-useless-escape": "error",
"no-useless-return": "error",
"no-void": "error",
"no-warning-comments": "warn",
"no-with": "error",
"prefer-promise-reject-errors": "error",
"radix": "error",
"require-await": "error",
"vars-on-top": "error",
"wrap-iife": ["error", "inside"],
"yoda": "error",
"no-console": "warn",
"no-var": "error",
"no-unused-vars": "warn",
"arrow-body-style": ["error", "as-needed"]
}
}
22 changes: 15 additions & 7 deletions backend-app/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const globalErrHandler = require("./middlewares/globalErrorHandler");
const AppError = require("./utils/appError");
const express = require("express");
const rateLimit = require("express-rate-limit");
const limiter = require("./middlewares/rate_limit");
const compression = require("compression");
const helmet = require("helmet");
const mongoSanitize = require("express-mongo-sanitize");
Expand Down Expand Up @@ -32,12 +32,6 @@ app.use(cors());
app.use(helmet());

// Limit request from the same API
const limiter = rateLimit({
max: 150,
windowMs: 60 * 60 * 1000,
message: "Too Many Request from this IP, please try again in an hour",
});
app.use("/api", limiter);

// Body parser, reading data from body into req.body
app.use(
Expand All @@ -62,10 +56,24 @@ app.use(hpp());
// Compress all responses
app.use(compression());

if (CURRENT_ENV.toLocaleLowerCase() === "production") {
//Limiting request form same IP
app.use("/api", limiter);
}

// Routes
app.use("/api/v1/users", userRoutes);
app.use("/api/v1/admin", adminRoutes);

//welcome page with the welcome message and env
app.get("/", (req, res) => {
res.status(200).json({
status: "success",
message: "Welcome to the backend app",
env: CURRENT_ENV,
});
});

// handle undefined Routes
app.use("*", (req, res, next) => {
const err = new AppError(404, "fail", "Route Not Found", req.path);
Expand Down
22 changes: 13 additions & 9 deletions backend-app/config/appConfig.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const { join } = require('path');
const dotenv = require('dotenv');
dotenv.config({ path: join(__dirname, '../.env') });
const { join } = require("path");
const dotenv = require("dotenv");
dotenv.config({ path: join(__dirname, "../.env") });

exports.logFilePath = join(__dirname, '../server-logs');
exports.CURRENT_ENV = process.env.NODE_ENV || 'development';
console.log(process.env.NODE_ENV);

exports.logFilePath = join(__dirname, "../server-logs");
exports.CURRENT_ENV = process.env.NODE_ENV || "development";
exports.DATABASE = process.env.MONGO_URI || "mongodb://127.0.0.1:27017";
exports.PORT = process.env.PORT || "5000"
exports.ADMIN_EMAIL = process.env.ADMIN_EMAIL || 'admin@gmail.com';
exports.ADMIN_PASSWORD = process.env.ADMIN_PASSWORD || 'admin123';
exports.PORT = process.env.PORT || "5000";
exports.ADMIN_EMAIL = process.env.ADMIN_EMAIL || "admin@gmail.com";
exports.ADMIN_PASSWORD = process.env.ADMIN_PASSWORD || "admin123";
exports.JWT_SECRET = process.env.JWT_SECRET || "sdfsdf";
exports.JWT_EXPIRES_IN = "360000";
exports.JWT_EXPIRES_IN = "360000";
// RATE_LIMIT_PER_HOUR
exports.RATE_LIMIT_PER_HOUR = process.env.RATE_LIMIT_PER_HOUR || 500;
8 changes: 8 additions & 0 deletions backend-app/middlewares/rate_limit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const rateLimit = require("express-rate-limit");
const { RATE_LIMIT_PER_HOUR } = require("../config/appConfig");

module.exports = rateLimit({
max: RATE_LIMIT_PER_HOUR,
windowMs: 60 * 60 * 1000,
message: "Too many requests from this IP, please try again in an hour!",
});
8 changes: 4 additions & 4 deletions backend-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"main": "app.js",
"scripts": {
"debug": "ndb server.js",
"dev": "NODE_ENV=DEVELOPMENT nodemon server.js",
"prod": "NODE_ENV=PRODUCTION node server.js",
"dev": "nodemon server.js NODE_ENV=DEVELOPMENT ",
"prod": "node server.js NODE_ENV=PRODUCTION",
"start": "nodemon server.js",
"test": "jest"
"test": "jest"
},
"author": "Bella Abdelouahab",
"license": "ISC",
Expand Down Expand Up @@ -38,4 +38,4 @@
"devDependencies": {
"nodemon": "^2.0.22"
}
}
}
13 changes: 0 additions & 13 deletions frontend-app/src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,12 @@
@tailwind utilities;

:root {
--foreground-rgb: 0, 0, 0;
--background-start-rgb: 214, 219, 220;
--background-end-rgb: 255, 255, 255;
}

@media (prefers-color-scheme: dark) {
:root {
--foreground-rgb: 255, 255, 255;
--background-start-rgb: 0, 0, 0;
--background-end-rgb: 0, 0, 0;
}
}

body {
color: rgb(var(--foreground-rgb));
background: linear-gradient(
to bottom,
transparent,
rgb(var(--background-end-rgb))
)
rgb(var(--background-start-rgb));
}

0 comments on commit 17e53a5

Please sign in to comment.