Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: drop setDefaultRoute and getDefaultRoute methods #4485

Merged
merged 1 commit into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions docs/Reference/Errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,6 @@ The router received an invalid url.

The router received an error when using asynchronous constraints.

#### FST_ERR_DEFAULT_ROUTE_INVALID_TYPE
<a id="FST_ERR_DEFAULT_ROUTE_INVALID_TYPE"></a>

The `defaultRoute` type should be a function.

#### FST_ERR_INVALID_URL
<a id="FST_ERR_INVALID_URL"></a>

Expand Down Expand Up @@ -382,4 +377,4 @@ Impossible to load plugin because the parent (mapped directly from `avvio`)
<a name="FST_ERR_PLUGIN_TIMEOUT"></a>
#### FST_ERR_PLUGIN_TIMEOUT

Plugin did not start in time. Default timeout (in millis): `10000`
Plugin did not start in time. Default timeout (in millis): `10000`
31 changes: 0 additions & 31 deletions docs/Reference/Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ describes the properties available in that options object.
- [ready](#ready)
- [listen](#listen)
- [addresses](#addresses)
- [getDefaultRoute](#getdefaultroute)
- [setDefaultRoute](#setdefaultroute)
- [routing](#routing)
- [route](#route)
- [hasRoute](#hasRoute)
Expand Down Expand Up @@ -1008,35 +1006,6 @@ const addresses = fastify.addresses()

Note that the array contains the `fastify.server.address()` too.

#### getDefaultRoute
<a id="getDefaultRoute"></a>

The `defaultRoute` handler handles requests that do not match any URL specified
by your Fastify application. This defaults to the 404 handler, but can be
overridden with [setDefaultRoute](#setdefaultroute). Method to get the
`defaultRoute` for the server:

```js
const defaultRoute = fastify.getDefaultRoute()
```

#### setDefaultRoute
<a id="setDefaultRoute"></a>

**Note**: The default 404 handler, or one set using `setNotFoundHandler`, will
never trigger if the default route is overridden. This sets the handler for the
Fastify application, not just the current instance context. Use
[setNotFoundHandler](#setnotfoundhandler) if you want to customize 404 handling
instead. Method to set the `defaultRoute` for the server:

```js
const defaultRoute = function (req, res) {
res.end('hello world')
}

fastify.setDefaultRoute(defaultRoute)
```

#### routing
<a id="routing"></a>

Expand Down
2 changes: 0 additions & 2 deletions fastify.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ function fastify (options) {
[kAvvioBoot]: null,
// routing method
routing: httpHandler,
getDefaultRoute: router.getDefaultRoute.bind(router),
setDefaultRoute: router.setDefaultRoute.bind(router),
// routes shorthand methods
delete: function _delete (url, options, handler) {
return router.prepareRoute.call(this, { method: 'DELETE', url, options, handler })
Expand Down
6 changes: 0 additions & 6 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,6 @@ const codes = {
'Unexpected error from async constraint',
500
),
FST_ERR_DEFAULT_ROUTE_INVALID_TYPE: createError(
'FST_ERR_DEFAULT_ROUTE_INVALID_TYPE',
'The defaultRoute type should be a function',
500,
TypeError
),
FST_ERR_INVALID_URL: createError(
'FST_ERR_INVALID_URL',
"URL must be a string. Received '%s'",
Expand Down
11 changes: 0 additions & 11 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const {
const {
FST_ERR_SCH_VALIDATION_BUILD,
FST_ERR_SCH_SERIALIZATION_BUILD,
FST_ERR_DEFAULT_ROUTE_INVALID_TYPE,
FST_ERR_DUPLICATED_ROUTE,
FST_ERR_INVALID_URL,
FST_ERR_SEND_UNDEFINED_ERR,
Expand Down Expand Up @@ -88,16 +87,6 @@ function buildRouting (options) {
route, // configure a route in the fastify instance
hasRoute,
prepareRoute,
getDefaultRoute: function () {
return router.defaultRoute
},
setDefaultRoute: function (defaultRoute) {
if (typeof defaultRoute !== 'function') {
throw new FST_ERR_DEFAULT_ROUTE_INVALID_TYPE()
}

router.defaultRoute = defaultRoute
},
routeHandler,
closeRoutes: () => { closing = true },
printRoutes: router.prettyPrint.bind(router),
Expand Down
43 changes: 0 additions & 43 deletions test/default-route.test.js

This file was deleted.

2 changes: 0 additions & 2 deletions test/types/instance.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,5 @@ const versionConstraintStrategy = {
expectType<void>(server.addConstraintStrategy(versionConstraintStrategy))
expectType<boolean>(server.hasConstraintStrategy(versionConstraintStrategy.name))

expectAssignable<DefaultRoute<RawRequestDefaultExpression, RawReplyDefaultExpression>>(server.getDefaultRoute())

expectType<FastifySchemaCompiler<any> | undefined>(server.validatorCompiler)
expectType<FastifySerializerCompiler<any> | undefined>(server.serializerCompiler)
1 change: 0 additions & 1 deletion types/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export type FastifyErrorCodes = Record<
'FST_ERR_FORCE_CLOSE_CONNECTIONS_IDLE_NOT_AVAILABLE' |
'FST_ERR_DUPLICATED_ROUTE' |
'FST_ERR_BAD_URL' |
'FST_ERR_DEFAULT_ROUTE_INVALID_TYPE' |
'FST_ERR_INVALID_URL' |
'FST_ERR_REOPENED_CLOSE_SERVER' |
'FST_ERR_REOPENED_SERVER' |
Expand Down
4 changes: 1 addition & 3 deletions types/instance.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FastifyBaseLogger } from './logger'
import { FastifyRegister } from './register'
import { FastifyReply } from './reply'
import { FastifyRequest } from './request'
import { DefaultRoute, RouteGenericInterface, RouteOptions, RouteShorthandMethod } from './route'
import { RouteGenericInterface, RouteOptions, RouteShorthandMethod } from './route'
import {
FastifySchema,
FastifySchemaCompiler,
Expand Down Expand Up @@ -168,8 +168,6 @@ export interface FastifyInstance<
register: FastifyRegister<FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider> & PromiseLike<undefined>>;

routing(req: RawRequest, res: RawReply): void;
getDefaultRoute(): DefaultRoute<RawRequest, RawReply>;
setDefaultRoute(defaultRoute: DefaultRoute<RawRequest, RawReply>): void;

route<
RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
Expand Down