Skip to content

Commit

Permalink
fix: conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-michelet committed Sep 22, 2024
2 parents 443026e + 7e524a5 commit 2580b5a
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
10 changes: 5 additions & 5 deletions @types/fastify/fastify.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Auth } from "../../src/schemas/auth.ts";
import { Auth } from '../../src/schemas/auth.ts'

declare module "fastify" {
export interface FastifyRequest {
user: Auth
}
declare module 'fastify' {
export interface FastifyRequest {
user: Auth
}
}
2 changes: 1 addition & 1 deletion @types/node/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ declare global {
}
}

export {};
export {}
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"@fastify/swagger-ui": "^5.0.1",
"@fastify/type-provider-typebox": "^5.0.0",
"@fastify/under-pressure": "^9.0.1",
"@fastify/vite": "^7.0.1",
"@sinclair/typebox": "^0.33.12",
"@vitejs/plugin-react": "^4.3.1",
"concurrently": "^9.0.1",
Expand All @@ -49,14 +48,12 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@types/node": "^22.0.0",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"eslint": "^9.4.0",
"@types/node": "^22.5.5",
"eslint": "^9.11.0",
"fastify-tsconfig": "^2.0.0",
"mysql2": "^3.10.1",
"mysql2": "^3.11.3",
"neostandard": "^0.11.5",
"tap": "^21.0.1",
"typescript": "^5.4.5"
"typescript": "^5.6.2"
}
}
10 changes: 7 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@ export default async function serviceApp (
'Unhandled error occurred'
)

const statusCode = err.statusCode ?? 500
reply.code(statusCode)
reply.code(err.statusCode ?? 500)

return { message: 'Internal Server Error' }
let message = 'Internal Server Error'
if (err.statusCode === 401) {
message = err.message
}

return { message }
})

// An attacker could search for valid URLs if your 404 error handling is not rate limited.
Expand Down
24 changes: 24 additions & 0 deletions src/routes/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {
FastifyPluginAsyncTypebox,
Type
} from '@fastify/type-provider-typebox'

const plugin: FastifyPluginAsyncTypebox = async (fastify) => {
fastify.get(
'/',
{
schema: {
response: {
200: Type.Object({
message: Type.String()
})
}
}
},
async function () {
return { message: 'Welcome to the official fastify demo!' }
}
)
}

export default plugin
14 changes: 14 additions & 0 deletions test/routes/home.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test } from 'node:test'
import assert from 'node:assert'
import { build } from '../helper.js'

test('GET /', async (t) => {
const app = await build(t)
const res = await app.inject({
url: '/'
})

assert.deepStrictEqual(JSON.parse(res.payload), {
message: 'Welcome to the official fastify demo!'
})
})

0 comments on commit 2580b5a

Please sign in to comment.