.env. The configure command writes it for you:
Terminal
.env
The site’s slug: the
acme in its key, fsk_acme_…, which the command reads from the key. A key
filed under another slug is refused, naming the right one.The site’s public origin:
https:// and the host it answers on, with no path, query or credentials.
A redirect is never followed; plain http:// reaches only localhost or a private service name.fsk_<site>_<key id>_<secret>, as the site showed it. An empty value is refused, never taken as the
public.fss_…, when the key signs. With a secret, the client signs every request it can, uploads by their
SHA-256. Signing requests lists which requests must be signed.start/env.ts, so a missing key or a mistyped URL stops the app at boot, and
the key and secret are Secrets that print as [redacted]:
start/env.ts
tld: false lets a local site such as http://localhost:4321 through.
Or keep the key in your database
The key and signing secret sealed in a table, replaced without touching
.env.The config file
The command also writesconfig/attract.ts. Every option is here, with what it starts as:
config/attract.ts
defineConfig checks the file as it loads, so a mistake (a default no site is filed under, a
negative timeout) stops the app at boot with one message naming the fix.
Ask for it
In a controller, service, listener or queue job, take the client in the constructor:app/controllers/blog_posts_controller.ts
const site = await app.container.make(SiteClient) (with
import app from '@adonisjs/core/services/app').
The default site
SiteClient reaches the default
The site
default names (FETCHSKI_ATTRACT_SITE), or, when that is unset, the one site
configured (with the key in the database, the table’s one row).SiteClients reaches any site
await sites.forSite('globex'): a client for that site, made on the spot (cheap: nothing is sent).No default, several sites: a clear error
No default site among acme, globex: set default in config/attract.ts (FETCHSKI_ATTRACT_SITE), or take SiteClients and call forSite('<slug>').Many sites, by slug
List each further site under its slug, beside the env one:config/attract.ts
start/env.ts as Env.schema.secret(). Then take the SiteClients
directory and ask it for each site by its slug:
app/services/sites_report.ts
SiteClient keeps reaching the default site. A slug nothing lists throws UnknownSite; with the
keys in the database, every row is a site (Key in the database).
Give tests a placeholder
Tests boot the app, sostart/env.ts checks the variables there too. Tests fake the client
(Testing) and never call the site, so a placeholder does:
.env.test
Keys stay secret
Secret until the client
Env.schema.secret() values print as [redacted], in logs and in node ace repl. Only the
package releases them, into the client.Never in the SDK's output
No error, log line or dump of the client holds a key (Keeping keys secret).
Next: key in the database
The key sealed under
APP_KEY, stored with one Ace command.