Docs / Building
Before You Go to Production
the settings to check before the first deploy.
Introduction #
Restify's defaults copy Restify for PHP, so a PHP application's clients keep working after the move. Some of those defaults are open: they suit a laptop, not a public server. Go through this page once before the first deploy, and again before a PHP application switches to Rust.
The checklist #
| Setting | Default | Set it to |
|---|---|---|
RESTIFY_MAX_PER_PAGE | No limit, as in PHP | The largest page a client needs, such as 100 |
RESTIFY_TOKEN_TTL | Tokens never expire, as in PHP | A number of minutes, such as 43200 for 30 days |
CACHE_STORE | memory, one store per process | database or redis |
| Trusted proxies | None | Your load balancer's addresses |
| CORS | Any origin under api/*, no cookies | Your frontend's origins |
APP_DEBUG | true in .env.example | false |
| Trusted hosts | The host of APP_URL | Every host your clients use |
RESTIFY_RELATED_MAX_DEPTH and RESTIFY_RELATED_MAX_PATHS | 3 and 20 | Keep them, or lower them |
Cap the page size #
A client chooses the page size with perPage or page[size]. Without a cap, perPage=100000 loads 100,000 rows in one request. Restify for PHP has no cap by default either, and PHP clients may rely on that, so Restify for Rust keeps it.
Set the cap in .env:
RESTIFY_MAX_PER_PAGE=100
A larger perPage then gets 100 rows. The cap also limits how many related rows a list loads for each relationship. See Pagination.
Let tokens expire #
A token from POST /api/login works until the user logs out, as in PHP. A stolen token works forever. Make tokens expire after a number of minutes:
RESTIFY_TOKEN_TTL=43200
See Sanctum tokens.
Share the rate limits between servers #
Login and registration are throttled as in PHP: 6 logins a minute for one email from one IP address, 30 logins a minute from one IP address, and 6 registrations a minute from one IP address. PHP doesn't let you change these numbers, so Restify doesn't either.
The counters live in the framework's default cache store. That store is memory unless CACHE_STORE says otherwise. The memory store belongs to one process and is emptied on each restart. With 4 servers, a client gets 4 times the limit, and a deploy resets it. Use a shared store:
CACHE_STORE=redis
See the framework's rate limiting guide.
Trust only your own proxies #
The rate limits count by IP address. Behind a load balancer, every request seems to come from the load balancer's address, so all clients share one limit. Tell the framework which proxies to trust, in src/app.rs:
.with_middleware(|middleware, _| {
middleware.trust_proxies(["10.0.0.0/8"]);
})
Don't trust "*" unless your load balancer replaces any X-Forwarded-For header the client sent. Otherwise a client can pick its own IP address and skip the limits. See the framework's guide on trusting proxies.
Know the registration limits #
POST /api/register checks what PHP's RestifyRegisterRequest checks:
| Key | Rules |
|---|---|
email | Required, an email address, at most 255 characters, not already used |
password | Required, confirmed, at least 6 characters |
name | No rule, as in PHP |
Restify keeps these rules so PHP clients keep working. A request body has the framework's size limit, so a name can't be endless. If your users table needs more, such as a length limit on name, serve your own register route instead of Restify::auth. See Authentication.
Choose who may call the API from a browser #
By default, the framework lets JavaScript on any website call routes under api/*, without cookies. Restify's routes are under api/, so any website can call them with a token it holds. If only your own frontend should, list its origins in src/config/cors.rs. See the framework's guide on CORS.
The MCP server refuses every other site's page, unless src/config/cors.rs lists the origin for its path: see Calling the MCP server from a browser.
Turn debug mode off #
With APP_DEBUG=true, a server error shows the error, its causes, the route and the request. Set it to false in production:
APP_DEBUG=false
See the framework's configuration guide.
Trust every host your clients use #
In production, the framework answers 400 to a request whose Host header isn't the host of APP_URL or one of its subdomains. List every other host your clients use. See Trust every host your clients use.
Limit how much ?related= loads #
Restify refuses a ?related= or include chain deeper than RESTIFY_RELATED_MAX_DEPTH (3) and a request that names more than RESTIFY_RELATED_MAX_PATHS (20) relationships, with a 422. Restify for PHP has no such limit. 0 turns a limit off. See How deep, and how many.
Know what your database decides #
Restify runs on SQLite, PostgreSQL, MySQL and MariaDB. A few answers depend on the database, in Restify for PHP and in Restify for Rust alike, so they don't change when you move from PHP to Rust on the same database. Check them when you change databases:
| What | SQLite | PostgreSQL | MySQL and MariaDB |
|---|---|---|---|
?search= and upper and lower case | Ignores the case of A to Z | Ignores case | Follows the column's collation: the usual ones ignore case and accents, a _bin one doesn't |
Where NULL goes when sorting ascending | First | Last | First |
| How text sorts | By the letters' codes: capitals first | By the database's locale | By the collation: the usual ones ignore case |
?group_by= a column that isn't the key | Works | 500 | 500 on MySQL (ONLY_FULL_GROUP_BY); works on MariaDB |
To make the search ignore case on every database, set RESTIFY_SEARCH_CASE_SENSITIVE=false. See Search.
On MariaDB, start DATABASE_URL with mariadb://, not mysql://, so the framework writes MariaDB's SQL.
On SQLite, put journal_mode=wal in the production DATABASE_URL too, if you turned on the write-ahead log: it is a setting of each environment's .env, not of the code. After the first write, sqlite3 <file> "PRAGMA journal_mode" answers wal. See Many token requests on SQLite.