Server services for programs
A program is only HTML, CSS and JavaScript running in the browser, so by itself it can't reach most websites (browsers block that unless the other site allows it) and it can't keep a secret such as an API key. Services let a program ask the Codesey server to do a small, safe set of things on its behalf.
Programs never contain server code. They declare what they need in manifest.json; uploading the program in the admin panel is the administrator's approval. A program can only use what it declared.
Declaring access #
{
"name": "Weather",
"permissions": ["http"],
"http": {
"endpoints": [
{ "host": "api.openweathermap.org", "methods": ["GET"],
"auth": { "in": "query", "name": "appid", "secret": "OWM_KEY" } },
{ "host": "geocoding-api.open-meteo.com" }
]
}
}
permissions:"http","web.read", or both. Anything else is ignored.http.endpoints: the exact host names the program may call. Host names only (no IP addresses, nolocalhost, no wildcards).methodsdefaults to["GET"]; listPOST,PUT,PATCHorDELETEif needed.auth(optional): the server adds an API key the program never sees.inisheaderorquery,nameis the header or parameter name,secretis the key's name, andprefix(optional) goes in front, for example"Bearer ". The administrator pastes the key under Admin → Services.
codesey.http #
const r = await codesey.http.get('https://api.example.com/v1/forecast?city=Berlin');
r.status; r.ok; r.json; r.body; r.headers['content-type'];
const data = await codesey.http.getJson(url); // throws unless the answer is 2xx
await codesey.http.post(url, { name: 'x' }); // JSON body
await codesey.http.request({ url, method: 'PUT', headers: { Accept: 'application/json' }, form: { a: 1 } });
A 4xx/5xx answer from the other site is returned (with ok: false), not thrown. Errors from Codesey itself (not declared, key missing, too slow, blocked) reject with a clear message.
Rules the server enforces:
- Only the declared hosts, and only the declared methods.
httpsonly (and only ports 80/443). - Redirects are followed (up to 2), but only to other declared hosts.
- The program can't set
Authorization,Cookie,Host,Origin,X-Forwarded-*and similar headers. - Request body up to 256 KB. Response up to 2 MB of text, JSON or XML (no images, no downloads). 10 second timeout.
- The server never connects to private or internal addresses, even if a declared host name points at one.
codesey.web #
const page = await codesey.web.read('https://example.com/article');
page.title; page.byline; page.siteName; page.url; page.excerpt;
page.html; // the article as clean, safe HTML (paragraphs, headings, lists, links, images); show it with innerHTML
page.text; page.images; page.words; page.minutes;
This returns the readable content of a public page, never the page itself: no scripts, forms, styles or tracking. It is a reader, not a proxy, and it is off until the administrator enables it (CODESEY_WEB_READER=true). It works well for articles, blogs, documentation and wikis. It doesn't work for pages that need JavaScript to show their content, pages behind a login, or sites that block servers.
Images in page.html are loaded by the visitor's browser straight from the original site. (The site's image server sees the visitor's address. A program can strip images if that matters.)
Limits and errors #
| Error | Meaning |
|---|---|
not_permitted |
The manifest didn't declare this service. |
host_not_declared / method_not_declared |
The URL or method isn't in the manifest. |
secret_missing |
The administrator hasn't pasted the API key yet. |
blocked_address |
The address is private or internal. |
unsupported_type |
The answer isn't text/JSON (or, for the reader, a web page). |
too_large / timeout / too_many_redirects |
The other site was too big, too slow or redirected too much. |
disabled / domain_blocked / domain_not_allowed |
The administrator's web reader settings don't allow it. |
rate_limited |
Too many requests in a short time. |
Rate limits: 120 service calls per minute per person, and 30 pages per minute for the reader.
For administrators #
- Admin → Services lists each uploaded program that asks for services, the hosts it may call, its API keys (set, replace or remove them; they are stored encrypted and never shown again), and the last 7 days of activity: counts per program, service and host. No users and no page addresses are recorded.
- The web reader is configured in
.env:
| Setting | Default | What it does |
|---|---|---|
CODESEY_WEB_READER |
false |
Turns the reader on. |
CODESEY_WEB_ALLOW |
(empty) | Comma-separated domains. If set, the reader may open only these (and their subdomains). |
CODESEY_WEB_BLOCK |
(empty) | Domains the reader must refuse. |
CODESEY_GATEWAY_TIMEOUT |
10 |
Seconds to wait for another site. |
- Sites see your server's address, not your visitors'.
CODESEY_GATEWAY_ALLOW_PRIVATE,CODESEY_GATEWAY_HOST_OVERRIDESandCODESEY_GATEWAY_PORTSexist for local development only. They let programs reach private networks. Never turn them on for a public site (the admin page shows a warning if they are on).