Skip to content

Commit

Permalink
[Task] #41 skip tests in rateLimiting
Browse files Browse the repository at this point in the history
  • Loading branch information
Type-Style committed Feb 13, 2024
1 parent f40a710 commit f403abc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"prebuild": "rm -rf dist/*",
"build": "npx tsc && cp -R httpdocs/ dist/",
"build:prod": "npx tsc -p ./tsconfig.prod.json && cp -R httpdocs/ dist/",
"start": "node dist/app.js",
"start": "LOCALHOST=127.0.0.1 LOCALHOSTv6=::1 dist/app.js",

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
"start:prod": "dist/app.js",
"dev": "rm -rf dist/* && cp -R httpdocs/ dist/ && nodemon src/app.ts",
"lint": "eslint . --fix",
"test": "jest"
Expand Down
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ app.use(function (req, res, next) { // limit request size limit when recieving d

// routes
app.get('/', (req, res) => {
console.log(req.ip + " - " + res.locals.ip);
res.send('Hello World, via TypeScript and Node.js! ' + res.locals.ip);
});

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import logger from '@src/scripts/logger';

const baseOptions: Partial<rateLimiterOptions & slowDownOptions> = {
windowMs: 30 * 60 * 1000,
skip: (req, res) => (res.locals.ip == process.env.LOCALHOST)
skip: (req, res) => (res.locals.ip == process.env.LOCALHOST, res.locals.ip == process.env.LOCALHOSTv6)
}

const baseSlowDownOptions: Partial<slowDownOptions> = {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe("GET /write", () => {

expect(entry.time.created).toBeGreaterThan(date.getTime());
expect(entry.time.diff).toBeGreaterThan(3.5);
expect(entry.time.diff).toBeLessThan(4);
expect(entry.time.diff).toBeLessThan(4.6);


const germanDayPattern = "(Montag|Dienstag|Mittwoch|Donnerstag|Freitag|Samstag|Sonntag)";
Expand Down

0 comments on commit f403abc

Please sign in to comment.