Configuring routes

Configuring routes in Kore happens in the Kore configuration inside of the domain configuration block.

Routes are evaluated from top to bottom. Routes can either contain a fixed string of be a regular expression.

domain * {
    route / {
        handler root_page
    }

    route /about/ {
        handler about_page
    }

    route ^.*$ {
        handler redirect
    }
}

In the example above the configuration specifies 2 fixed routes and one regex route that captures all the other paths and sends them to some redirection function.

Parameter configuration

If you wish to receive parameters via a route you must define them in the configuration and specify how they should be validated.

Validation is not optional.

You define how to validate the parameters inside of the route context.

# First we must define a validator (in the global config)
validator v_number regex ^[0-9]$

domain * {
    route / {
        handler root_page
        methos get post
        validate qs:get id v_number
        validate post id v_number
    }
}

The validate syntax is as follows:

validate method parameter validator

Where method is the lowercase method (eg: post, get) and optionally prefixed with qs: indicating the query string should be validated with this parameters.

If validation for a parameter fails it is filtered out.

results matching ""

    No results matching ""