← Files RivetARCHIVED FILE

node_modules/rivet-design/dist/prototype-host.js

3.27 KB · Nov 7, 2026 · 13:16 UTC

↓ Download file

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const zod_1 = require("zod");
const index_core_1 = require("./index-core");
const prototypeHost_1 = require("./routes/prototypeHost");
const BundleStore_1 = require("./services/BundleStore");
const SupabaseAuthService_1 = require("./services/SupabaseAuthService");
const proxy_1 = require("./config/proxy");
const hostedLogging_1 = require("./utils/hostedLogging");
(0, hostedLogging_1.enableHostedLogPrivacy)();
const log = (0, index_core_1.createLogger)('PrototypeHostBootstrap');
const envSchema = zod_1.z.object({
    PORT: zod_1.z.coerce.number().int().positive().default(4100),
    PROTOTYPE_HOST_PUBLIC_URL: zod_1.z
        .string()
        .min(1)
        .default(proxy_1.DEFAULT_PROTOTYPE_HOST_URL),
    PROTOTYPE_BUNDLE_ROOT: zod_1.z
        .string()
        .min(1)
        .default('/var/rivet-prototype-bundles'),
    PROTOTYPE_MAX_BUNDLE_MB: zod_1.z.coerce.number().int().positive().default(25),
    SUPABASE_URL: zod_1.z.string().min(1),
    SUPABASE_ANON_KEY: zod_1.z.string().min(1),
});
const MALFORMED_REQUEST_STATUS = 400;
const OVERSIZED_REQUEST_STATUS = 413;
const UNSUPPORTED_ENCODING_STATUS = 415;
const REQUEST_FAILURE_STATUS = 500;
const handleRequestError = (error, _req, res, _next) => {
    log.warn('Prototype request failed', error);
    if (res.headersSent) {
        res.destroy();
        return;
    }
    const errorType = error && typeof error === 'object' && 'type' in error
        ? error.type
        : undefined;
    if (errorType === 'entity.parse.failed') {
        res
            .status(MALFORMED_REQUEST_STATUS)
            .json({ error: 'Invalid request body' });
        return;
    }
    if (errorType === 'entity.too.large') {
        res
            .status(OVERSIZED_REQUEST_STATUS)
            .json({ error: 'Request body too large' });
        return;
    }
    if (errorType === 'encoding.unsupported') {
        res
            .status(UNSUPPORTED_ENCODING_STATUS)
            .json({ error: 'Unsupported request body encoding' });
        return;
    }
    res.status(REQUEST_FAILURE_STATUS).json({ error: 'Request failed' });
};
const main = async () => {
    const env = envSchema.parse(process.env);
    await (0, BundleStore_1.ensureBundleRoot)(env.PROTOTYPE_BUNDLE_ROOT);
    const app = (0, express_1.default)();
    app.use(express_1.default.json({ limit: `${env.PROTOTYPE_MAX_BUNDLE_MB + 5}mb` }));
    app.use((0, prototypeHost_1.createPrototypeHostRouter)({
        store: new BundleStore_1.DiskBundleStore(env.PROTOTYPE_BUNDLE_ROOT),
        auth: new SupabaseAuthService_1.SupabaseAuthService(),
        publicBaseUrl: env.PROTOTYPE_HOST_PUBLIC_URL,
        maxBundleBytes: env.PROTOTYPE_MAX_BUNDLE_MB * 1024 * 1024,
    }));
    app.use(handleRequestError);
    app.listen(env.PORT, () => {
        log.info(`Prototype Preview Host listening on ${env.PORT} (bundles: ${env.PROTOTYPE_BUNDLE_ROOT})`);
    });
    await new Promise(() => { });
};
void main().catch((error) => {
    log.error('Prototype host startup failed', error);
    process.exitCode = 1;
});
//# sourceMappingURL=prototype-host.js.map

SHA-256: 641af19ecda8d77e2908a4a16c107fa64ac74d7c54c9bc8705dd2b5878ae9e42