Skip to content

Commit f459c17

Browse files
Merge pull request #5 from tinyhttp/blacklist
Ignore feature
2 parents 76abdd9 + e4d481d commit f459c17

File tree

9 files changed

+412
-335
lines changed

9 files changed

+412
-335
lines changed

.github/workflows/ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ jobs:
1010
bun-version: latest
1111
- run: bun install
1212
- run: bun test:coverage
13-
- run: bun test:report
1413
- name: Coveralls
1514
uses: coverallsapp/github-action@master
1615
with:
1716
github-token: ${{ secrets.GITHUB_TOKEN }}
18-
path-to-lcov: ./lcov.info
17+
path-to-lcov: ./coverage/lcov.info
1918
build:
2019
runs-on: ubuntu-latest
2120
steps:

.husky/commit-msg

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
3-
41
bunx commitlint --config commitlint.config.mjs --edit "$1"

.husky/pre-commit

-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
3-
41
bun check && bun run build && bun run test

bun.lock

+120-81
Large diffs are not rendered by default.

package.json

+6-8
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,22 @@
3434
},
3535
"scripts": {
3636
"build": "tsc",
37-
"test": "tsx tests/index.test.ts",
38-
"test:coverage": "c8 tsx --test tests/index.test.ts",
39-
"test:report": "c8 report --reporter=text-lcov > lcov.info",
37+
"test": "vitest run --dir tests",
38+
"test:coverage": "vitest run --dir tests --coverage",
4039
"check": "biome check",
4140
"check:fix": "biome check --write",
42-
"prepare": "husky install"
41+
"prepare": "husky"
4342
},
4443
"devDependencies": {
4544
"@biomejs/biome": "^1.9.4",
4645
"@commitlint/cli": "^19.7.1",
4746
"@commitlint/config-conventional": "^19.7.1",
4847
"@tinyhttp/app": "^2.5.2",
4948
"@types/node": "^20.17.22",
50-
"c8": "^10.1.3",
51-
"expect": "^29.7.0",
49+
"@vitest/coverage-v8": "^3.0.7",
5250
"husky": "^9.1.7",
5351
"supertest-fetch": "^2.0.0",
54-
"tsx": "^4.19.3",
55-
"typescript": "^5.8.2"
52+
"typescript": "^5.8.2",
53+
"vitest": "^3.0.7"
5654
}
5755
}

src/index.ts

+10-9
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ export enum LogLevel {
1212
log = 'log'
1313
}
1414

15-
export interface LoggerOptions {
16-
methods?: string[]
17-
output?: {
15+
export type LoggerOptions = Partial<{
16+
methods: string[]
17+
output: {
1818
color: boolean
1919
filename?: string
2020
callback: (string: string) => void
2121
level?: LogLevel
2222
}
23-
timestamp?: boolean | { format?: string }
24-
emoji?: boolean
25-
ip?: boolean
26-
}
23+
timestamp: boolean | { format?: string }
24+
emoji: boolean
25+
ip: boolean
26+
ignore: string[]
27+
}>
2728

2829
const compileArgs = (
2930
args: (string | number)[],
@@ -63,6 +64,7 @@ const compileArgs = (
6364

6465
export const logger = (options: LoggerOptions = {}) => {
6566
const methods = options.methods ?? METHODS
67+
const ignore = options.ignore ?? []
6668
const output = options.output ?? { callback: console.log, color: true, level: null }
6769
let filelogger = null
6870
if (options.output?.filename) {
@@ -71,8 +73,7 @@ export const logger = (options: LoggerOptions = {}) => {
7173
return (req: Request, res: Response, next?: () => void) => {
7274
res.on('finish', () => {
7375
const args: (string | number)[] = []
74-
// every time
75-
if (methods.includes(req.method)) {
76+
if (methods.includes(req.method) && !ignore.some((url) => req.url.startsWith(url))) {
7677
const s = res.statusCode.toString()
7778
let stringToLog = ''
7879
if (!output.color) {

0 commit comments

Comments
 (0)