import { existsSync } from 'node:fs';
import { join, resolve } from 'node:path';
import express from 'express';
export function isWebAssetsBuilt(assetsDir) {
    const resolvedAssetsDir = resolve(assetsDir);
    return existsSync(join(resolvedAssetsDir, 'index.html')) && existsSync(join(resolvedAssetsDir, 'assets'));
}
export function assertWebAssetsBuilt(assetsDir) {
    const resolvedAssetsDir = resolve(assetsDir);
    if (!isWebAssetsBuilt(resolvedAssetsDir)) {
        throw new Error(`Built web assets not found at ${resolvedAssetsDir}. Run yarn build before starting heddle daemon.`);
    }
}
export function installWebStaticRoutes(app, assetsDir) {
    const resolvedAssetsDir = resolve(assetsDir);
    const indexPath = join(resolvedAssetsDir, 'index.html');
    app.use(express.static(resolvedAssetsDir, {
        immutable: true,
        index: false,
        maxAge: '1y',
    }));
    app.get(/.*/, (_request, response) => {
        response.sendFile(indexPath, {
            headers: {
                'Cache-Control': 'no-store',
            },
        });
    });
}
//# sourceMappingURL=static.js.map