Skip to content

Commit

Permalink
fix: improve code on index.ts and update biome
Browse files Browse the repository at this point in the history
  • Loading branch information
matteovivona committed Feb 20, 2025
1 parent 288df6f commit 2267524
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 76 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"homepage": "https://github.com/ducktors/arecibo#readme",
"devDependencies": {
"@biomejs/biome": "1.6.1",
"@biomejs/biome": "^1.9.4",
"@commitlint/cli": "^19.7.1",
"@commitlint/config-conventional": "^19.7.1",
"@commitlint/lint": "^19.7.1",
Expand All @@ -65,9 +65,7 @@
"ts-node": "^10.9.2",
"typescript": "^5.7.3"
},
"files": [
"/lib"
],
"files": ["/lib"],
"dependencies": {
"fastify-plugin": "^5.0.1"
},
Expand Down
94 changes: 47 additions & 47 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 19 additions & 25 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import fp from 'fastify-plugin'
import { readinessSchema, livenessSchema } from './schema'
import { areciboMessage } from './arecibo-message'

const READINESS_URL = '/arecibo/readiness'
const LIVENESS_URL = '/arecibo/liveness'
const ROUTES = {
READINESS: '/arecibo/readiness',
LIVENESS: '/arecibo/liveness',
} as const

const defaultMessage = areciboMessage

const defaultResponse =
(message: string): RouteHandler =>
(_, reply) => {
reply.type('text/html').send(message)
}
function createResponseHandler(message: string): RouteHandler {
return (_, reply) => reply.type('text/html').send(message)
}

interface Opts extends FastifyPluginOptions {
message?: string
Expand All @@ -32,25 +30,21 @@ interface Opts extends FastifyPluginOptions {
const arecibo: FastifyPluginCallback<Opts> = fp<Opts>(
(fastify, opts, next) => {
const {
message = defaultMessage,
readinessURL = READINESS_URL,
livenessURL = LIVENESS_URL,
message = areciboMessage,
readinessURL = ROUTES.READINESS,
livenessURL = ROUTES.LIVENESS,
readinessCallback = createResponseHandler(message),
livenessCallback = createResponseHandler(message),
logLevel = 'info',
} = opts

const readinessCallback = opts.readinessCallback || defaultResponse(message)
const livenessCallback = opts.livenessCallback || defaultResponse(message)

fastify.get(
readinessURL,
{ schema: readinessSchema, logLevel },
readinessCallback,
)
fastify.get(
livenessURL,
{ schema: livenessSchema, logLevel },
livenessCallback,
)
fastify
.get(
readinessURL,
{ schema: readinessSchema, logLevel },
readinessCallback,
)
.get(livenessURL, { schema: livenessSchema, logLevel }, livenessCallback)

next()
},
Expand Down

0 comments on commit 2267524

Please sign in to comment.