Skip to content

Mounting the router on a route group #33

@matthewcheok

Description

@matthewcheok

Suppose we had some route configuration like:

func routes(_ app: Application) throws {
  let unprotectedAPI = app.grouped("api")

  let tokenProtectedAPI = unprotectedAPI
    .grouped(Token.authenticator())
    .grouped(UserModel.guardMiddleware())
  
  try tokenProtectedAPI
    .grouped("users")
    .register(collection: UserController())
}

How would we convert this to use a parser-backed router? This is generally useful for chaining on middlewares to specific route groups, i.e. if we wanted everything behind the api path to require token-based authentication.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions