"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const CompactdApplication_1 = require("./CompactdApplication");
const path = require("path");
const storyboard_1 = require("storyboard");
const fs = require("fs");
const config_1 = require("./config");
const serveStatic = require("serve-static");
const pkg = require('../../package.json');
class ProdApplication extends CompactdApplication_1.CompactdApplication {
    constructor(host, port) {
        super(host, port);
    }
    configure() {
        super.configure();
        const versionFile = path.join(config_1.default.get('dataDirectory'), '_version');
        if (!fs.existsSync(versionFile)) {
            storyboard_1.mainStory.fatal('compactd', 'Please upgrade your database to the latest version');
            storyboard_1.mainStory.info('compactd', 'You may want to use compactd --upgrade');
            process.exit(1);
        }
        const version = fs.readFileSync(versionFile).toString();
        if (version !== pkg.version) {
            storyboard_1.mainStory.fatal('compactd', 'Please upgrade your database to the latest version');
            storyboard_1.mainStory.info('compactd', 'You may want to use compactd --upgrade');
            process.exit(1);
        }
    }
    route() {
        super.route();
        this.app.use(serveStatic(path.join(__dirname, '../../client/dist'), {
            dotfiles: 'ignore'
        }));
        this.app.get('*', function (req, res) {
            res.sendFile(path.join(__dirname, '../../client/dist/index.html'));
        });
    }
}
exports.ProdApplication = ProdApplication;
//# sourceMappingURL=ProdApplication.js.map