Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/AnkanSaha/outers into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkanSaha committed Mar 8, 2024
2 parents 2f00620 + 54e24dc commit 6b7a8ce
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,13 @@ app.use("/api", Middleware.JWTValidator("FieldName", Token), MainRouter); // use
```javascript
const { Middleware } = require("outers"); // import the package

app.use("/api", Middleware.RequestCounter(true, true, true, true, true), MainRouter); // count the number of requests in NodeJS with the Middleware function
app.use(
"/api",
Middleware.RequestCounter(true, true, true, true, true),
MainRouter,
); // count the number of requests in NodeJS with the Middleware function
```
- Note : You can pass true/false in all parameters of the function, by default it is set to true, if you set it to true then it will count the number of requests in the console
- Note : The First Parameter is SaveIP which is used to save the IP Address in the Request Object, by default it is set to true, if you set it to true then it will save the IP Address in the Request Object
Expand All @@ -470,11 +475,14 @@ app.use("/api", Middleware.RequestCounter(true, true, true, true, true), MainRou
- Note : The Third Parameter is SaveRequestTime which is used to save the Request Time in the Request Object, by default it is set to true, if you set it to true then it will save the Request Time in the Request Object
- Note : The Fourth Parameter is SaveContentType which is used to save the Content Type in the Request Object, by default it is set to true, if you set it to true then it will save the Content Type in the Request Object
- Note : The Fourth Parameter is SaveContentType which is used to save the Content Type in the Request Object, by default it is set to true, if you set it to true then it will save the Content Type in the Request Object
- Note : The Fifth Parameter is SaveMethod which is used to save the Method in the Request Object, by default it is set to true, if you set it to true then it will save the Method in the Request Object
## License
MIT
```

```
12 changes: 6 additions & 6 deletions source/Cluster/class/CreateClusterByClass.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class CreateClusterByClass {
NumberOfWorkers?: number,
BeforeListenFunctions?: any[],
AfterListenFunctions?: any[],
FunctionMiddlewares?: any[]
FunctionMiddlewares?: any[],
) {
this.#ExpressServer = ExpressServer ?? express(); // Express Server Instance
this.#PORT = PORT; // Active Server Instance
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class CreateClusterByClass {
1024 /
1024 /
1024
).toFixed(2)} GB Free Ram : ${cpus()[0].model}`
).toFixed(2)} GB Free Ram : ${cpus()[0].model}`,
);

// Create a worker according to the number that is specified
Expand All @@ -120,7 +120,7 @@ export default class CreateClusterByClass {
ClusterConfig.on("online", (worker) => {
green(`🚀 Worker ${worker.process.pid} started 🚀`);
blue(
`Environment Variables Loaded Successfully in Worker : ${worker.process.pid}`
`Environment Variables Loaded Successfully in Worker : ${worker.process.pid}`,
);
this.#GlobalResponseObject.ActiveWorker++; // Increment Active Worker Count by 1
yellow(`Worker ${worker.process.pid} is listening`);
Expand All @@ -133,7 +133,7 @@ export default class CreateClusterByClass {
ClusterConfig.fork();
green(`🚀 Worker ${worker.process.pid} restarted 🚀`);
blue(
`Environment Variables Loaded Successfully in Worker : ${worker.process.pid}`
`Environment Variables Loaded Successfully in Worker : ${worker.process.pid}`,
);
this.#GlobalResponseObject.ActiveWorker++; // Increment Active Worker Count by 1
yellow(`Worker ${worker.process.pid} is listening`);
Expand All @@ -143,7 +143,7 @@ export default class CreateClusterByClass {
this.#EnableTrustProxy === true
? this.#ExpressServer.set("trust proxy", true)
: yellow(
"Trust Proxy is not enabled, if you are working behind a proxy, please enable it to get the real IP Address"
"Trust Proxy is not enabled, if you are working behind a proxy, please enable it to get the real IP Address",
);

// Apply Function Middlewares to Express Server Instance like CORS, Body Parser, etc.
Expand Down Expand Up @@ -182,7 +182,7 @@ export default class CreateClusterByClass {
await ListenFunction(); // Run Function one by one
}
}
}
},
); // Start Server on Port

// Return the Active Server Instance in Response Object
Expand Down
10 changes: 5 additions & 5 deletions source/Cluster/function/CreateClusterByFunction.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async function Config(
EnableTrustProxy: boolean = true, // Enable Trust Proxy
BeforeListenFunctions: any[] = [], // Any Functions to run before listen
AfterListenFunctions: any[] = [], // Any Functions to run after listen
FunctionMiddlewares: any[] = [] // Any Middlewares to apply
FunctionMiddlewares: any[] = [], // Any Middlewares to apply
): Promise<ResponseObject | undefined> {
// Check if User Provided Express Server or not
if (!ExpressServer || ExpressServer === undefined) {
Expand Down Expand Up @@ -68,7 +68,7 @@ export default async function Config(
1024 /
1024 /
1024
).toFixed(2)} GB Free Ram : ${cpus()[0].model}`
).toFixed(2)} GB Free Ram : ${cpus()[0].model}`,
);

// Create a worker according to the number that is specified
Expand All @@ -81,7 +81,7 @@ export default async function Config(
ClusterConfig.on("online", (worker) => {
green(`🚀 Worker ${worker.process.pid} started 🚀`);
blue(
`Environment Variables Loaded Successfully in Worker : ${worker.process.pid}`
`Environment Variables Loaded Successfully in Worker : ${worker.process.pid}`,
);
GlobalResponseObject.ActiveWorker++; // Increment Active Worker Count by 1
yellow(`Worker ${worker.process.pid} is listening`);
Expand All @@ -94,7 +94,7 @@ export default async function Config(
ClusterConfig.fork();
green(`🚀 Worker ${worker.process.pid} restarted 🚀`);
blue(
`Environment Variables Loaded Successfully in Worker : ${worker.process.pid}`
`Environment Variables Loaded Successfully in Worker : ${worker.process.pid}`,
);
GlobalResponseObject.ActiveWorker++; // Increment Active Worker Count by 1
yellow(`Worker ${worker.process.pid} is listening`);
Expand All @@ -104,7 +104,7 @@ export default async function Config(
EnableTrustProxy
? ExpressServer.set("trust proxy", () => true)
: yellow(
"Trust Proxy is not enabled, if you are working behind a proxy, please enable it to get the real IP Address"
"Trust Proxy is not enabled, if you are working behind a proxy, please enable it to get the real IP Address",
);

// Apply Function Middlewares to Express Server Instance like CORS, Body Parser, etc.
Expand Down
2 changes: 1 addition & 1 deletion source/Config/Constant/Middleware.Constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ export const IPAllowedMethods = ["PUT", "POST", "PATCH", "DELETE"]; // Allowed M
export const AllowedMethods = [...IPAllowedMethods, "OPTIONS"]; // Allowed Methods

// Constants for Request Counter Storage
export const TodayDate = new Date().toLocaleDateString(); // Get Today's Date
export const TodayDate = new Date().toLocaleDateString(); // Get Today's Date
4 changes: 2 additions & 2 deletions source/Middlewares/User Counter/Base.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Serve } from "../../Config/outer"; // Importing Serve
export const StorageInstance = new Storage(
"Request-Counter-details-for-nodejs",
999999, // 999999 MB = 1TB
"Request-Counter-details-for-nodejs"
"Request-Counter-details-for-nodejs",
);

// Main middleware function
Expand All @@ -17,7 +17,7 @@ export default function (
SaveUserAgent: boolean = true,
SaveRequestTime: boolean = true,
SaveContentType: boolean = true,
SaveMethod: boolean = true
SaveMethod: boolean = true,
) {
return async (Request: Request, Response: Response, Next: NextFunction) => {
const GetPreviousData = await StorageInstance.Get(TodayDate); // Get previous data
Expand Down

0 comments on commit 6b7a8ce

Please sign in to comment.