Tuft is a route-based framework similar to hapi. When a client requests a particular path, a Tuft server will first determine if there is a route that matches that path. If there is, Tuft will generate a response based on a user-defined handler.

To add a route, call the route map's .set() method.

app.set('/foo', { status: 200 })

In the above example, whenever a client submits a request with the path '/foo', the server will respond with a 200 OK status code and no body.

To add a route that only responds to a specific request method, prepend the path with the request method and a space.

app.set('GET /foo', { status: 200 })

See the TuftRouteMap API section for more information on adding routes.

Custom 404 handling

If a client requests a route that doesn't exist, the server will respond to the client with a 404 Not Found status code and an empty response body by default. You can override this behavior, or customize the 404 response, by adding a "catch-all" route.

app.set('/{**}', {
  status: 404,
  json: {
    statusCode: 404,
    message: 'Not Found'

The '{**}' in the path of the example above is a wildcard glob that matches all text, including the text of sub-paths. Therefore, adding a route of '/{**}' with no other path segments will match all routes that have not already been matched by a more specific route.