-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from utsav00/issues/32-lint
Issue 32: Add a pre-commit hook for lint checking and styling
- Loading branch information
Showing
103 changed files
with
7,860 additions
and
7,691 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
import { rateLimit } from 'express-rate-limit'; | ||
import { Request,Response } from 'express'; | ||
import { Request, Response } from 'express'; | ||
import rateLimitResponse from './consts/RateLimitResponse'; | ||
|
||
// WINDOW_SIZE and WINDOW_TIME can be configured in .env.example file | ||
const RATELIMIT_WINDOWSIZE=parseInt(process.env.RATELIMIT_WINDOWSIZE); | ||
const RATELIMIT_WINDOWTIME=parseInt(process.env.RATELIMIT_WINDOWTIME); | ||
const RATELIMIT_WINDOWSIZE = parseInt(process.env.RATELIMIT_WINDOWSIZE); | ||
const RATELIMIT_WINDOWTIME = parseInt(process.env.RATELIMIT_WINDOWTIME); | ||
|
||
// middleware for rate limiting application usage. | ||
export const applicationRateLimiter=rateLimit({ | ||
max:RATELIMIT_WINDOWSIZE, | ||
windowMs:RATELIMIT_WINDOWTIME, | ||
legacyHeaders:false, | ||
standardHeaders:true, // sends standard headers after the limit get over | ||
message:(req:Request,res:Response)=>{ | ||
const ratelimitObject:rateLimitResponse={ | ||
id: "too_many_requests", | ||
generatedAt:Date.now(), | ||
message: "API Rate limit exceeded." | ||
} | ||
export const applicationRateLimiter = rateLimit({ | ||
max: RATELIMIT_WINDOWSIZE, | ||
windowMs: RATELIMIT_WINDOWTIME, | ||
legacyHeaders: false, | ||
standardHeaders: true, // sends standard headers after the limit get over | ||
message: (req: Request, res: Response) => { | ||
const ratelimitObject: rateLimitResponse = { | ||
id: 'too_many_requests', | ||
generatedAt: Date.now(), | ||
message: 'API Rate limit exceeded.', | ||
}; | ||
res.json(ratelimitObject).status(429); | ||
} | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/sh | ||
# | ||
# An example hook script to verify what is about to be committed. | ||
# Called by "git commit" with no arguments. The hook should | ||
# exit with non-zero status after issuing an appropriate message if | ||
# it wants to stop the commit. | ||
# | ||
# To enable this hook, rename this file to "pre-commit" and add it under `.git/hooks/`. | ||
|
||
# Fixes and throws error if cannot | ||
npm run lint-fix | ||
|
||
# Redirect output to stderr. | ||
exec 1>&2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import app from './app' | ||
import app from './app'; | ||
|
||
const port = 3000; | ||
|
||
app.listen(port, () => { | ||
console.log(`Mock API is running on port ${port}.`); | ||
console.log(`Vist Mock API in the browser http://localhost:${port}.`); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import Address from '../consts/Address'; | ||
|
||
const getRandomAddresses = (addressCount : number = 1, country : string = 'uk') : Address[] => { | ||
const addresses : Address[] = []; | ||
|
||
for (let index = 0; index < addressCount; index++) { | ||
addresses.push({ | ||
houseNumber: faker.address.buildingNumber(), | ||
addressLine1: faker.address.secondaryAddress(), | ||
addressLine2: faker.address.street(), | ||
city: faker.address.cityName(), | ||
postcode: country !== "usa" ? faker.address.zipCode() : null, | ||
zipcode: country === "usa" ? faker.address.zipCode() : null, | ||
country | ||
}) | ||
} | ||
return addresses; | ||
} | ||
const getRandomAddresses = (addressCount: number = 1, country: string = 'uk'): Address[] => { | ||
const addresses: Address[] = []; | ||
|
||
export default getRandomAddresses; | ||
for (let index = 0; index < addressCount; index++) { | ||
addresses.push({ | ||
houseNumber: faker.address.buildingNumber(), | ||
addressLine1: faker.address.secondaryAddress(), | ||
addressLine2: faker.address.street(), | ||
city: faker.address.cityName(), | ||
postcode: country !== 'usa' ? faker.address.zipCode() : null, | ||
zipcode: country === 'usa' ? faker.address.zipCode() : null, | ||
country, | ||
}); | ||
} | ||
return addresses; | ||
}; | ||
|
||
export default getRandomAddresses; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ enum AnimalType { | |
Rabbit, | ||
Rodent, | ||
Snake, | ||
Type | ||
Type, | ||
} | ||
|
||
export default AnimalType | ||
export default AnimalType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.