Skip to content

Show a page only in development

Debug pages, preview regions and sample notes help while you build an application. In production they must not exist. dev() is a condition that is true only when the engine runs with -dev. You write it in an ordinary condition. The same .mtd files run in both modes, and the engine answers dev() per request.

Start the engine in development mode on your machine:

Terminal window
matterdata serve -dir tenants -domain localhost -dev

-dev also drops the Secure flag from cookies, so plain http works. Production nodes never run with -dev, so dev() is false there.

Put where dev() in the page’s access rule.

page debug "Import probe" {
route: /debug
access: admin where dev()
report of signups {
columns: name, token
}
}

In development, an admin opens /debug. In production, the same request answers 404, like a row that the reader cannot see. A member gets 403 in both modes, because the role rule fails first. The 404 also covers the page’s CSV export and every other address on it.

The engine answers 404 when dev() alone makes the access condition false, as in admin where dev() or admin where status.open and dev(). A condition that production can still meet, such as admin where dev() or status.open, only narrows the rows of the page’s lists. A condition that does not read dev() does the same. The page then opens, with the rows that the condition admits.

Do not list the page in a nav. The menu asks who may open a page and never runs the row condition, so production would show a link that answers 404. The compiler refuses a nav entry for a page that reads dev() and tells you to leave it out. Open the page by its address.

Show a region or a note only in development

Section titled “Show a region or a note only in development”

Use where: on a region and when: on a note.

page signups "Signups" {
route: /signups
access: admin
report of signups where dev() {
columns: name, token
}
note {
when: dev()
text: "Seeded token for this run: check the token column."
}
}

In production, the note is not rendered, and the report shows no rows. The report itself still appears, as an empty table. To remove a region completely, put it on its own page and gate that page.

deny when dev() refuses in development. Use it in front of an action with a real-world effect, such as a transition that sends an email, and name that effect in a comment.

table mails "Mails" {
display: subject
subject text required "Subject"
lifecycle status "Status" {
state draft default "Draft"
state sent "Sent"
transition send draft -> sent "Send" {
access: admin
// Sends real mail. Refused on a laptop.
deny when dev() "No mail from a development node."
}
}
}

To allow an action only in development, name dev() in the transition’s own rule: access: admin where dev(). In production, a crafted request for it answers 404 before any set or hook runs.

Do not write deny when <rule> and dev(). The rule then applies only in development and protects nothing in production. Write the real rule without dev().

The compiler refuses dev() where the answer must be the same on every node: check, require … when, a computed column, an aggregate’s where:, default:, the value of a set, and show_when:. Each message names the site and a repair. See dev for the list and the reasons.

A page that is gone in production is also gone for anonymous visitors. access: public where dev() admits visitors on your laptop and answers 404 to them in production. It never gives a visitor a role.

Website privacy policy