mirror of
https://github.com/HeyPuter/puter.git
synced 2026-11-26 15:48:41 +00:00
* refactor(util): shared helpers for hosts, timeouts, chunking, paging, shutdown flush and codes Adds normalizeHost/getPuterHostedDomains, withTimeout, chunk, nowSeconds, isMissingTable, clampLimit/parsePageQuery/pageEnvelope, finalFlush, parseRetryAfterMs/doublingBackoffMs, randomCode, sweepInBatches, hashPassword/generateEmailConfirmCode, requestIp and isTemporaryAccount, and removes util exports nothing called. * refactor(clients,core): drop unread alarm state and dead shutdown paths, share host helpers DynamoDB batches still throttled after the retries answer 503 db_unavailable. * refactor(stores): one cache read per miss, tombstones on every write, batch methods for callers above The multi-check permission cache is read with pipelined GETs. claimOwnership, replaceDataUrlIcon and setLabel tombstone their keys. updateMetadata merges in one statement. App stats reject an unknown period and cap grouped answers. * refactor(services): fewer serial round trips in permission, share, metering and events paths checkMany no longer caches a check that threw. Account deletion revokes its sessions first. OIDC email_verified strings are read as booleans. Events limits, FS service types and the events worker deployer live under services. * refactor(drivers): one teardown path for workers, shared credit hold and provider helpers A URL input and a generated-media download have a deadline and a size cap. Azure chat clients take the shared client options. xAI and Mistral chat send tools through toolsToWire and honor apiBaseUrl. * refactor(controllers): shared download, paging and second-factor helpers, store methods for raw SQL /batch answers a non-HTTP op error generically and logs it. /fs/search returns the client entry shape. The unused /puterai/video/proxy route is removed. * refactor: thumbnails accept raster types only, boot failure exits, docs for new limits * fix: sessions stay listed after a rename, token grants follow the whole revoke cascade, app delete in one transaction - listSessions asks the primary about rows marked as changed, so a renamed session stays on the list under its new label. - The revoke cascade reports the access tokens it revoked, and their grants are dropped at any depth. The read before each revoke is gone. - App delete records the deletion, clears filetype associations and deletes the row in one transaction. - A local worker deploy waits for the runtime to start, so a script it cannot load fails the deploy. - Speechify plain text: an & that starts no XML entity and a < that starts no complete tag are escaped. - The events forward queue's byte bound counts UTF-8 bytes. - Without a dedicated store, thumbnails stay in the default bucket. - AppStore.invalidateWrittenByUid for writers that hold the uid. - subdomainFromHost takes the configured domain list; the sorting wrapper only tests called is removed. - Changelog and alarm docs match the code. * fix: cache pipelines fall back to single commands across shards, TURN records metered one by one, allowance baseline kept - execTogether runs single-key cache commands in one round trip and, on a cluster that cannot route them in one pipeline, sends each on its own. The row cache, tombstone reads and writes, the FS entry backfill, the permission check cache and the revoked-session cache write use it. - TURN usage ingestion makes one metering call per user with each record as its own usage, so one malformed record does not affect the others. - The allowance settlement keeps the baseline fold for month records without allowanceUsed. - Speechify plain text keeps a self-closing tag without attributes. * fix(localworker): a deploy waits for the runtime to start and a failed cold start answers 502 A script the runtime cannot load fails the deploy. What was serving before goes back in place, and a first request for such a worker answers 502. * fix(subdomains): the sites rooted under a folder are read in name order, a page at a time subdomainsRootedUnder takes the name to start past, so a caller pages through every match instead of stopping at one query's limit.
557 lines
22 KiB
JavaScript
557 lines
22 KiB
JavaScript
/*
|
|
* Copyright (C) 2024-present Puter Technologies Inc.
|
|
*
|
|
* This file is part of Puter.
|
|
*
|
|
* Puter is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import {
|
|
isAccessTokenActor,
|
|
isAccountContext,
|
|
isAppActor,
|
|
viaWorkerOf,
|
|
} from '../../core/actor.js';
|
|
import { HttpError } from '../../core/http/HttpError.js';
|
|
import {
|
|
APP_ICON_SIZES,
|
|
ICON_DATA_URL_MIME_ALLOWLIST,
|
|
isTrustedIconHost,
|
|
} from '../../util/appIcon.js';
|
|
import { toAppReadView } from '../../util/appView.js';
|
|
import { PuterController } from '../types.js';
|
|
import DEFAULT_APP_ICON from './default-app-icon.js';
|
|
|
|
/**
|
|
* Desktop boot reads the app list and individual app records repeatedly, so the
|
|
* ceiling is set well above normal boot traffic and exists to catch a runaway
|
|
* client rather than to pace one.
|
|
*
|
|
* "Repeatedly" is the operative word: an app record is read on launch, on
|
|
* permission checks, and again by anything resolving an app by name, so these
|
|
* accumulate against whatever else a session is doing rather than arriving on
|
|
* their own. Sized for a session working hard, not for a person clicking.
|
|
*/
|
|
const APP_READ_LIMIT = {
|
|
scope: 'app-read',
|
|
limit: 1_800,
|
|
window: 60_000,
|
|
key: 'user',
|
|
};
|
|
|
|
/**
|
|
* Unauthenticated icon serving; no actor to key on, so the bucket is the
|
|
* address — and an address is a NAT, a campus or a carrier gateway that can
|
|
* hold hundreds of desktops. Each dashboard load pulls its app icons at once,
|
|
* so a single burst from one network is already thousands of requests.
|
|
* Responses are publicly cacheable and usually a redirect, so the ceiling is
|
|
* not protecting bandwidth; it is there so a client looping on a broken icon
|
|
* can't spin unbounded.
|
|
*/
|
|
const APP_ICON_LIMIT = {
|
|
scope: 'app-icon',
|
|
limit: 12_000,
|
|
window: 60_000,
|
|
key: 'ip',
|
|
};
|
|
|
|
// Shared by `GET /apps/:name` (pipe-separated) and `POST /query/app`, which
|
|
// both fan out one lookup per name.
|
|
const APP_LOOKUP_MAX_ENTRIES = 200;
|
|
const APP_LOOKUP_MAX_SELECTOR_LEN = 200;
|
|
|
|
/** What `/apps/:name` reports for an app no launch gate applies to. */
|
|
const PUBLIC_APP_ACCESS = { hasAccess: true, checkedBy: 'core/public-app' };
|
|
|
|
/**
|
|
* REST endpoints for app management. CRUD goes through the apps driver; the
|
|
* read routes use AppService for visibility and views, as the driver does.
|
|
*/
|
|
export class AppController extends PuterController {
|
|
// In-flight background app-open writes. Tracked only so tests and
|
|
// shutdown can wait for them — the request path never does.
|
|
#pendingOpenWrites = new Set();
|
|
|
|
/**
|
|
* Record an app open. `app_opens` is analytics: it backs the recent-apps
|
|
* list and the open counters, and no response field is derived from it. The
|
|
* client posts this without awaiting and updates its own recent list
|
|
* optimistically, so holding a response open for a primary write only added
|
|
* latency to the launch that write is measuring.
|
|
*
|
|
* Failures are logged, never surfaced — a dropped stat must not turn into a
|
|
* failed app open.
|
|
*
|
|
* @param {string} appUid
|
|
* @param {number} userId
|
|
* @returns {Promise<void>} Settles when the write and event emit finish
|
|
*/
|
|
#recordAppOpen(appUid, userId) {
|
|
const ts = Math.floor(Date.now() / 1000);
|
|
const work = (async () => {
|
|
try {
|
|
await this.stores.app.recordOpen(appUid, userId, ts);
|
|
} catch (e) {
|
|
console.warn('[rao] insert failed:', e);
|
|
}
|
|
|
|
try {
|
|
this.clients.event?.emitAndWait(
|
|
'app.opened',
|
|
{ app_uid: appUid, user_id: userId, ts },
|
|
{},
|
|
);
|
|
} catch {
|
|
// event emission best-effort
|
|
}
|
|
})();
|
|
|
|
this.#pendingOpenWrites.add(work);
|
|
work.finally(() => this.#pendingOpenWrites.delete(work));
|
|
return work;
|
|
}
|
|
|
|
/** Await every in-flight app-open write. */
|
|
async drainPendingAppOpens() {
|
|
await Promise.allSettled([...this.#pendingOpenWrites]);
|
|
}
|
|
|
|
registerRoutes(
|
|
/** @type {import('../../core/http/PuterRouter').PuterRouter} */ router,
|
|
) {
|
|
// GET /apps — list apps owned by the current user
|
|
router.get(
|
|
'/apps',
|
|
{
|
|
subdomain: 'api',
|
|
requireUserActor: true,
|
|
allowFullAccessToken: true,
|
|
rateLimit: APP_READ_LIMIT,
|
|
},
|
|
async (req, res) => {
|
|
const apps = await this.drivers.apps.select({
|
|
predicate: ['user-can-edit'],
|
|
});
|
|
res.json(apps);
|
|
},
|
|
);
|
|
|
|
// GET /apps/nameAvailable?name=foo
|
|
router.get(
|
|
'/apps/nameAvailable',
|
|
{
|
|
subdomain: 'api',
|
|
requireAuth: true,
|
|
// Answers "does this name exist?" for any name, so it is a
|
|
// name-enumeration oracle however cheap it is to serve.
|
|
// Mirrors the `isNameAvailable` budget on AppDriver.
|
|
rateLimit: {
|
|
scope: 'app-name-available',
|
|
limit: 60,
|
|
window: 60_000,
|
|
key: 'user',
|
|
},
|
|
},
|
|
async (req, res) => {
|
|
const name = req.query?.name;
|
|
if (!name || typeof name !== 'string') {
|
|
throw new HttpError(
|
|
400,
|
|
'Missing or invalid `name` query param',
|
|
{ legacyCode: 'bad_request' },
|
|
);
|
|
}
|
|
const available = await this.drivers.apps.isNameAvailable(name);
|
|
res.json({ name, available });
|
|
},
|
|
);
|
|
|
|
// POST /rao — record a recent app open. When an app-under-user
|
|
// actor calls this, the app id is already on the token — clients
|
|
// don't re-send it in the body. Fall back to the acting app's uid
|
|
// before 400-ing for a missing body field.
|
|
//
|
|
// Authorization: only two callers are trusted to report opens —
|
|
// 1. the account acting as itself (plain session or full-access
|
|
// token), e.g. the GUI launching apps on behalf of the user;
|
|
// 2. the app-under-user actor for the app being reported.
|
|
// Everything else — scoped and app-issued access tokens, asset
|
|
// tokens, app actors reporting for a *different* app — is denied,
|
|
// otherwise any authenticated party could inflate another app's
|
|
// open count.
|
|
router.post(
|
|
'/rao',
|
|
{
|
|
subdomain: 'api',
|
|
requireAuth: true,
|
|
rateLimit: APP_READ_LIMIT,
|
|
},
|
|
async (req, res) => {
|
|
const actor = req.actor;
|
|
// Server-side code running as the account (a worker, an events
|
|
// handler) is not someone opening the app. Answered as success
|
|
// so deployed workers, which still ask, don't log a failure.
|
|
if (viaWorkerOf(actor)) {
|
|
res.json({});
|
|
return;
|
|
}
|
|
const bodyAppUid = req.body?.app_uid;
|
|
const callerAppUid = actor?.effectiveApp?.uid;
|
|
const app_uid =
|
|
typeof bodyAppUid === 'string' && bodyAppUid.length > 0
|
|
? bodyAppUid
|
|
: callerAppUid;
|
|
if (!app_uid || typeof app_uid !== 'string') {
|
|
throw new HttpError(400, 'Missing or invalid `app_uid`', {
|
|
legacyCode: 'bad_request',
|
|
});
|
|
}
|
|
|
|
// Shared credentials shouldn't drive analytics counters.
|
|
if (isAccessTokenActor(actor) && !isAccountContext(actor)) {
|
|
throw new HttpError(
|
|
403,
|
|
'This token cannot report app opens',
|
|
{ legacyCode: 'forbidden' },
|
|
);
|
|
}
|
|
|
|
if (isAppActor(actor) && app_uid !== callerAppUid) {
|
|
throw new HttpError(
|
|
403,
|
|
'App actors can only report opens for their own app',
|
|
{ legacyCode: 'forbidden' },
|
|
);
|
|
}
|
|
|
|
const app = await this.stores.app.getByUid(app_uid);
|
|
if (!app)
|
|
throw new HttpError(404, 'App not found', {
|
|
legacyCode: 'not_found',
|
|
});
|
|
|
|
// Validation and authorization are settled by this point, so
|
|
// the caller learns the outcome now and the stats write lands
|
|
// on its own. See `#recordAppOpen`.
|
|
this.#recordAppOpen(app_uid, req.actor.user.id);
|
|
|
|
res.json({});
|
|
},
|
|
);
|
|
|
|
// GET /apps/:name — returns the app(s) by name.
|
|
// Supports pipe-separated names for batch lookup: /apps/foo|bar|baz
|
|
router.get(
|
|
'/apps/:name',
|
|
{
|
|
subdomain: 'api',
|
|
requireUserActor: true,
|
|
allowFullAccessToken: true,
|
|
rateLimit: APP_READ_LIMIT,
|
|
},
|
|
async (req, res) => {
|
|
const raw = req.params.name;
|
|
const names = raw.split('|').filter(Boolean);
|
|
if (names.length > APP_LOOKUP_MAX_ENTRIES) {
|
|
throw new HttpError(
|
|
400,
|
|
`at most ${APP_LOOKUP_MAX_ENTRIES} app names per request`,
|
|
{ legacyCode: 'bad_request' },
|
|
);
|
|
}
|
|
|
|
const actor = req.actor;
|
|
const appsByName = await this.stores.app.getByNames(
|
|
names.filter(
|
|
(name) => name.length <= APP_LOOKUP_MAX_SELECTOR_LEN,
|
|
),
|
|
);
|
|
const readable = await this.services.app.filterReadable(
|
|
[...new Set(appsByName.values())],
|
|
actor,
|
|
);
|
|
const views = await this.services.app.views(readable, actor, {
|
|
source: 'appsRoute',
|
|
});
|
|
const shapedByUid = new Map(
|
|
readable.map((app, i) => {
|
|
const shaped = toAppReadView(app, views[i], {
|
|
viewer: actor.user,
|
|
});
|
|
shaped.privateAccess ??= PUBLIC_APP_ACCESS;
|
|
return [app.uid, shaped];
|
|
}),
|
|
);
|
|
const results = names.map(
|
|
(name) =>
|
|
shapedByUid.get(appsByName.get(name)?.uid) ?? null,
|
|
);
|
|
|
|
// Single-name requests return the app directly; batch returns an array
|
|
if (names.length === 1) {
|
|
const single = results[0];
|
|
if (!single)
|
|
throw new HttpError(404, 'App not found', {
|
|
legacyCode: 'not_found',
|
|
});
|
|
return res.json(single);
|
|
}
|
|
res.json(results);
|
|
},
|
|
);
|
|
|
|
// -- POST /query/app ----------------------------------------
|
|
// Batch marketplace-style lookup by name or UID.
|
|
//
|
|
// Access rules: only apps the caller has a legitimate reason to
|
|
// see are returned — public (`approved_for_listing`), owned by
|
|
// the caller, or readable per `AppService.filterReadable` (for
|
|
// protected apps, a granted permission). Everything else is
|
|
// silently skipped so the endpoint can't be used to enumerate
|
|
// existence of private / unapproved apps by guessing names.
|
|
//
|
|
// Response shape is intentionally narrow and mirrors v1 — no
|
|
// internal identifiers (mysql `id`, `owner_user_id`), no
|
|
// `index_url`, no admin flags. Developer `metadata` is
|
|
// included for public/owned apps only, consistent with
|
|
// marketplace semantics.
|
|
|
|
router.post(
|
|
'/query/app',
|
|
{
|
|
subdomain: 'api',
|
|
requireAuth: true,
|
|
rateLimit: APP_READ_LIMIT,
|
|
},
|
|
async (req, res) => {
|
|
const appList = Array.isArray(req.body) ? req.body : [];
|
|
if (appList.length > APP_LOOKUP_MAX_ENTRIES) {
|
|
throw new HttpError(
|
|
400,
|
|
`request body must contain at most ${APP_LOOKUP_MAX_ENTRIES} selectors`,
|
|
{ legacyCode: 'bad_request' },
|
|
);
|
|
}
|
|
|
|
const actor = req.actor;
|
|
const selectors = appList.filter(
|
|
(selector) =>
|
|
typeof selector === 'string' &&
|
|
selector.length > 0 &&
|
|
selector.length <= APP_LOOKUP_MAX_SELECTOR_LEN,
|
|
);
|
|
const isUid = (selector) => selector.startsWith('app-');
|
|
const [byUid, byName] = await Promise.all([
|
|
this.stores.app.getByUids(selectors.filter(isUid)),
|
|
this.stores.app.getByNames(
|
|
selectors.filter((s) => !isUid(s)),
|
|
),
|
|
]);
|
|
const found = selectors
|
|
.map((s) => (isUid(s) ? byUid.get(s) : byName.get(s)))
|
|
.filter(Boolean);
|
|
|
|
// Unapproved apps the caller doesn't own surface only when
|
|
// the caller may read them (one batched grant check).
|
|
const isListed = (app) =>
|
|
app.owner_user_id === actor.user?.id ||
|
|
Boolean(app.approved_for_listing);
|
|
const readable = new Set(
|
|
await this.services.app.filterReadable(
|
|
[...new Set(found.filter((app) => !isListed(app)))],
|
|
actor,
|
|
),
|
|
);
|
|
const visible = found.filter(
|
|
(app) => isListed(app) || readable.has(app),
|
|
);
|
|
const filetypesByAppId =
|
|
await this.stores.app.getFiletypeAssociationsByIds(
|
|
visible.map((app) => app.id),
|
|
);
|
|
|
|
const results = visible.map((app) => ({
|
|
uuid: app.uid,
|
|
name: app.name,
|
|
title: app.title,
|
|
description: app.description,
|
|
metadata: app.metadata,
|
|
tags:
|
|
typeof app.tags === 'string' ? app.tags.split(',') : [],
|
|
created: app.timestamp,
|
|
associations: filetypesByAppId.get(app.id) ?? [],
|
|
}));
|
|
|
|
res.json(results);
|
|
},
|
|
);
|
|
|
|
// -- GET /app-icon/:app_uid(/:size) -------------------------
|
|
// Serve app icon — data URL decoded inline, HTTP URL redirected.
|
|
//
|
|
// ⚠ FLAG: Missing sharp-based resize pipeline; serves the original.
|
|
|
|
// Neutering headers for any response that echoes an icon byte
|
|
// stream on the main origin. `image/svg+xml` is in our MIME
|
|
// allow-list — it's a legitimate image format, and our own
|
|
// default icon is SVG — but SVGs can carry `<script>` tags
|
|
// that execute when the response is loaded as a top-level
|
|
// document (e.g. victim clicks a phishing link pointing at
|
|
// `/app-icon/app-<uid>`). `nosniff` only blocks MIME sniffing;
|
|
// an honestly-declared `image/svg+xml` still renders + runs.
|
|
//
|
|
// `Content-Security-Policy: sandbox` drops the response into an
|
|
// opaque sandboxed browsing context: no scripts, no same-origin,
|
|
// no forms — regardless of the declared type. `<img src>` loads
|
|
// are unaffected because image decoding happens in a restricted
|
|
// mode that already ignores embedded scripts.
|
|
const setIconSecurityHeaders = (res) => {
|
|
res.set('X-Content-Type-Options', 'nosniff');
|
|
res.set('Content-Security-Policy', "default-src 'none'; sandbox;");
|
|
};
|
|
|
|
// Serves the default app icon data URL by decoding its base64 body
|
|
// and responding with the declared MIME type (SVG).
|
|
const serveDefaultIcon = (res) => {
|
|
const commaIdx = DEFAULT_APP_ICON.indexOf(',');
|
|
const mime =
|
|
DEFAULT_APP_ICON.slice(5, DEFAULT_APP_ICON.indexOf(';')) ||
|
|
'image/png';
|
|
setIconSecurityHeaders(res);
|
|
res.set('Content-Type', mime);
|
|
res.set('Cache-Control', 'public, max-age=3600');
|
|
res.send(
|
|
Buffer.from(DEFAULT_APP_ICON.slice(commaIdx + 1), 'base64'),
|
|
);
|
|
};
|
|
|
|
const serveIcon = async (req, res) => {
|
|
let appUid = String(req.params.app_uid ?? '');
|
|
const size = Number(req.params.size ?? 128);
|
|
if (!appUid) {
|
|
res.status(400).send('Missing app_uid');
|
|
return;
|
|
}
|
|
if (!APP_ICON_SIZES.includes(size)) {
|
|
res.status(400).send('Invalid size');
|
|
return;
|
|
}
|
|
if (!appUid.startsWith('app-')) appUid = `app-${appUid}`;
|
|
|
|
const app = await this.stores.app.getByUid(appUid);
|
|
const icon = app?.icon;
|
|
|
|
// If the icon isn't an inline data URL, try to serve it from the
|
|
// `/system/app_icons/` directory on the hosting subdomain. The
|
|
// resolver picks the sized variant when it exists and falls back
|
|
// to the un-resized original, so apps that only have the original
|
|
// PNG (common for rows imported with a pre-existing HTTP icon
|
|
// URL) don't 404 on `<uid>-<size>.png`.
|
|
const isInline =
|
|
typeof icon === 'string' &&
|
|
(icon.startsWith('data:') || !/^https?:\/\//i.test(icon));
|
|
if (!isInline) {
|
|
const redirectUrl =
|
|
await this.services.appIcon.resolveIconRedirectUrl(
|
|
appUid,
|
|
size,
|
|
);
|
|
if (redirectUrl) {
|
|
res.set('Cache-Control', 'public, max-age=900');
|
|
return res.redirect(302, redirectUrl);
|
|
}
|
|
// No local file — fall back to the raw `icon` column URL
|
|
if (
|
|
typeof icon === 'string' &&
|
|
/^https?:\/\//i.test(icon) &&
|
|
isTrustedIconHost(icon, this.config)
|
|
) {
|
|
res.set('Cache-Control', 'public, max-age=900');
|
|
return res.redirect(302, icon);
|
|
}
|
|
}
|
|
|
|
if (!icon) {
|
|
serveDefaultIcon(res);
|
|
return;
|
|
}
|
|
|
|
// Data URL — decode and serve directly
|
|
if (icon.startsWith('data:')) {
|
|
const commaIdx = icon.indexOf(',');
|
|
if (commaIdx === -1) {
|
|
serveDefaultIcon(res);
|
|
return;
|
|
}
|
|
const semiIdx = icon.indexOf(';');
|
|
const mimeEnd =
|
|
semiIdx !== -1 && semiIdx < commaIdx ? semiIdx : commaIdx;
|
|
const mime = icon.slice(5, mimeEnd).toLowerCase();
|
|
if (!ICON_DATA_URL_MIME_ALLOWLIST.includes(mime)) {
|
|
serveDefaultIcon(res);
|
|
return;
|
|
}
|
|
setIconSecurityHeaders(res);
|
|
res.set('Content-Type', mime);
|
|
// Same freshness as the redirect path above — this is the
|
|
// same resource, just served inline because no CDN file
|
|
// exists yet. A 60s TTL made every app launch re-fetch the
|
|
// icon over a connection the launch itself is competing for.
|
|
res.set('Cache-Control', 'public, max-age=900');
|
|
res.send(Buffer.from(icon.slice(commaIdx + 1), 'base64'));
|
|
|
|
// Trigger background generation so next request hits the CDN
|
|
this.clients.event.emit(
|
|
'app.new-icon',
|
|
{
|
|
app_uid: appUid,
|
|
data_url: icon,
|
|
},
|
|
{},
|
|
);
|
|
return;
|
|
}
|
|
|
|
// Fallback
|
|
serveDefaultIcon(res);
|
|
};
|
|
|
|
// Icons are <img src> targets from the GUI (root) AND resolved via
|
|
// api_base_url in app summaries. Register on both so either origin
|
|
// works without a cross-subdomain redirect.
|
|
router.get(
|
|
'/app-icon/:app_uid',
|
|
{ subdomain: ['api', ''], rateLimit: APP_ICON_LIMIT },
|
|
serveIcon,
|
|
);
|
|
router.get(
|
|
'/app-icon/:app_uid/:size',
|
|
{ subdomain: ['api', ''], rateLimit: APP_ICON_LIMIT },
|
|
serveIcon,
|
|
);
|
|
}
|
|
|
|
onServerStart() {}
|
|
/**
|
|
* Let outstanding stats writes finish before the process goes away —
|
|
* otherwise a deploy silently drops every open recorded in the seconds
|
|
* before it.
|
|
*/
|
|
async onServerPrepareShutdown() {
|
|
await this.drainPendingAppOpens();
|
|
}
|
|
|
|
onServerShutdown() {}
|
|
}
|