diff --git a/build.js b/build.js index cb06687..4fbbd50 100644 --- a/build.js +++ b/build.js @@ -24,7 +24,6 @@ esbuild.build({ entryPoints, logLevel: 'info', outdir: 'build', - minify: true, bundle: true, platform: 'node' }) diff --git a/package.json b/package.json index 1273a2e..6ccdab2 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "scripts": { "prepare": "husky install", "dev": "nodemon", - "build": "rm -rf build && esbuild `find src \\( -name '*.ts' \\)` --platform=node --outdir=build --bundle --minify", + "build": "rm -rf build && esbuild `find src \\( -name '*.ts' \\)` --platform=node --outdir=build --bundle", "build:windows": "rm -rf build && node ./build.js", "format": "prettier --write 'src/**/*.{js,ts,json,md}'", "lint": "prettier --check 'src/**/*.{js,ts,json,md}' && eslint --ignore-path .gitignore .", @@ -35,9 +35,9 @@ "typescript": "^4.6.4" }, "dependencies": { + "@fastify/autoload": "^4.0.0", + "@fastify/sensible": "^4.0.0", "fastify": "^3.29.0", - "fastify-autoload": "^3.13.0", - "fastify-plugin": "^3.0.1", - "fastify-sensible": "^3.2.0" + "fastify-plugin": "^3.0.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 896cbb1..212abc6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4,6 +4,8 @@ specifiers: '@commitlint/cli': ^16.2.4 '@commitlint/config-conventional': ^16.2.4 '@commitlint/cz-commitlint': ^16.2.4 + '@fastify/autoload': ^4.0.0 + '@fastify/sensible': ^4.0.0 '@types/node': ^17.0.30 '@typescript-eslint/eslint-plugin': ^5.21.0 '@typescript-eslint/parser': ^5.21.0 @@ -14,9 +16,7 @@ specifiers: eslint-config-prettier: ^8.5.0 eslint-plugin-prettier: ^4.0.0 fastify: ^3.29.0 - fastify-autoload: ^3.13.0 fastify-plugin: ^3.0.1 - fastify-sensible: ^3.2.0 husky: ^7.0.4 inquirer: ^8.2.4 lint-staged: ^12.4.1 @@ -26,10 +26,10 @@ specifiers: typescript: ^4.6.4 dependencies: + '@fastify/autoload': 4.0.0 + '@fastify/sensible': 4.0.0 fastify: 3.29.0 - fastify-autoload: 3.13.0 fastify-plugin: 3.0.1 - fastify-sensible: 3.2.0 devDependencies: '@commitlint/cli': 16.2.4 @@ -289,10 +289,29 @@ packages: ajv: 6.12.6 dev: false + /@fastify/autoload/4.0.0: + resolution: {integrity: sha512-mne+IEjcMa1UsypjjyXq5WMj0rTM7JTv6mxBD2o/wq9o/v6Eeyo1bCCnRAglbw/vc9IjQp5CxMg/n5lJmXR8sQ==} + dependencies: + pkg-up: 3.1.0 + semver: 7.3.7 + dev: false + /@fastify/error/2.0.0: resolution: {integrity: sha512-wI3fpfDT0t7p8E6dA2eTECzzOd+bZsZCJ2Hcv+Onn2b7ZwK3RwD27uW2QDaMtQhAfWQQP+WNK7nKf0twLsBf9w==} dev: false + /@fastify/sensible/4.0.0: + resolution: {integrity: sha512-iK9Xi03nyiiDviDRH6XoR/F9c80LxSbhDfkg4rXvYNfDdlef7L2QnY8GUGEN/WcjlYq4Gh7o7BJk7CqQUlGm8g==} + engines: {node: '>=10.0.0'} + dependencies: + fast-deep-equal: 3.1.3 + fastify-plugin: 3.0.1 + forwarded: 0.2.0 + http-errors: 2.0.0 + type-is: 1.6.18 + vary: 1.1.2 + dev: false + /@humanwhocodes/config-array/0.9.5: resolution: {integrity: sha512-ObyMyWxZiCu/yTisA7uzx81s40xR2fD5Cg/2Kq7G02ajkNubJf6BopgDTmDyc3U7sXpNKM8cYOw7s7Tyr+DnCw==} engines: {node: '>=10.10.0'} @@ -1527,9 +1546,9 @@ packages: isobject: 3.0.1 dev: true - /depd/1.1.2: - resolution: {integrity: sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=} - engines: {node: '>= 0.6'} + /depd/2.0.0: + resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} + engines: {node: '>= 0.8'} dev: false /detect-file/1.0.0: @@ -2140,43 +2159,10 @@ packages: resolution: {integrity: sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==} dev: false - /fastify-autoload/3.12.0: - resolution: {integrity: sha512-qm8HG8V24A0AdcIjGMMTnyKQj6yzEbdcXHbWjzPtYPReGo4D4Ki7oRLDocYQJVpaOxlcLJSbadfMhZTu3+G6oQ==} - dependencies: - pkg-up: 3.1.0 - semver: 7.3.7 - dev: false - - /fastify-autoload/3.13.0: - resolution: {integrity: sha512-+Dbsf7wUxf9KLBHnbcdI1MTUGPHAnjWnbbq1bZm4+b2ghX+goK8HBkWOpS4JK1GAiripoDoyUBw18wu8uDZKuA==} - dependencies: - fastify-autoload-deprecated: /fastify-autoload/3.12.0 - process-warning: 1.0.0 - dev: false - /fastify-plugin/3.0.1: resolution: {integrity: sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA==} dev: false - /fastify-sensible/3.1.2: - resolution: {integrity: sha512-fS8GeY6db3q38GzWOoZMggrw9yHOoXdHv1Pgnorvv18uDrmh1iL8gP9/cqdWzZRM1J3fYvcHsfV2t4BXQF2+sw==} - engines: {node: '>=10.0.0'} - dependencies: - fast-deep-equal: 3.1.3 - fastify-plugin: 3.0.1 - forwarded: 0.2.0 - http-errors: 1.8.1 - type-is: 1.6.18 - vary: 1.1.2 - dev: false - - /fastify-sensible/3.2.0: - resolution: {integrity: sha512-Y6hW5fRviGUXf5r5xEuqfnX5Zz1UEam1nGCkFH62r1wgVrfNjY5zNhfgKA23+zO6AcrSW6PQN5vXj9sJ2SBQ2w==} - dependencies: - fastify-sensible-deprecated: /fastify-sensible/3.1.2 - process-warning: 1.0.0 - dev: false - /fastify/3.29.0: resolution: {integrity: sha512-zXSiDTdHJCHcmDrSje1f1RfzTmUTjMtHnPhh6cdokgfHhloQ+gy0Du+KlEjwTbcNC3Djj4GAsBzl6KvfI9Ah2g==} dependencies: @@ -2690,14 +2676,14 @@ packages: resolution: {integrity: sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==} dev: true - /http-errors/1.8.1: - resolution: {integrity: sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==} - engines: {node: '>= 0.6'} + /http-errors/2.0.0: + resolution: {integrity: sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==} + engines: {node: '>= 0.8'} dependencies: - depd: 1.1.2 + depd: 2.0.0 inherits: 2.0.4 setprototypeof: 1.2.0 - statuses: 1.5.0 + statuses: 2.0.1 toidentifier: 1.0.1 dev: false @@ -4495,9 +4481,9 @@ packages: object-copy: 0.1.0 dev: true - /statuses/1.5.0: - resolution: {integrity: sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=} - engines: {node: '>= 0.6'} + /statuses/2.0.1: + resolution: {integrity: sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==} + engines: {node: '>= 0.8'} dev: false /string-argv/0.3.1: diff --git a/src/index.ts b/src/index.ts index e4bca94..a643ac7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { join } from 'path' import Fastify from 'fastify' -import autoLoad from 'fastify-autoload' +import autoLoad from '@fastify/autoload' const fastify = Fastify({ logger: true diff --git a/src/plugins/sensible.ts b/src/plugins/sensible.ts index f3d3245..fb33816 100644 --- a/src/plugins/sensible.ts +++ b/src/plugins/sensible.ts @@ -1,5 +1,5 @@ import fp from 'fastify-plugin' -import sensible, { SensibleOptions } from 'fastify-sensible' +import sensible, { SensibleOptions } from '@fastify/sensible' /** * This plugins adds some utilities to handle http errors diff --git a/src/routes/bad-request/index.ts b/src/routes/bad-request/index.ts new file mode 100644 index 0000000..10d1cc8 --- /dev/null +++ b/src/routes/bad-request/index.ts @@ -0,0 +1,10 @@ +import { FastifyPluginAsync } from 'fastify' + +const badRequest: FastifyPluginAsync = async (fastify): Promise => { + // Note: using an arrow function will break the binding of this to the FastifyInstance. + fastify.get('/', async function (req, reply) { + reply.badRequest() + }) +} + +export default badRequest diff --git a/src/routes/examples/index.ts b/src/routes/examples/index.ts index 68a0ea1..6e46ef5 100644 --- a/src/routes/examples/index.ts +++ b/src/routes/examples/index.ts @@ -1,8 +1,9 @@ import { FastifyPluginAsync } from 'fastify' -const example: FastifyPluginAsync = async (fastify, opts): Promise => { - fastify.get('/', async function (request, reply) { - return 'this is an example' +const example: FastifyPluginAsync = async (fastify): Promise => { + // Note: using an arrow function will break the binding of this to the FastifyInstance. + fastify.get('/', async function (req, reply) { + return this.someSupport() }) }